<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<?xml-stylesheet href="_c74_vig.xsl" type="text/xsl"?>
<vignette name="The File Object" package="Max">
	<h1>The File Object</h1>
	<p>
	The File object provides a means of reading and writing files from Javasccript.
	</p>
	<h2>File Constructor</h2>
	<code language="javascript">
	  f = new File(filename, access, typelist);
	</code>
	<p>
	filename can be a file in the Max search path, an absolute path, or a relative path. Acceptable values for access can be "read", "write", or "readwrite". The default value for access is "read". Acceptable values for typelist are four character filetype codes listed in the file max-fileformats.txt, which is located at /Library/Application Support/Cycling ’74 on Macintosh and C:\Program Files\Common Files\Cycling ’74 on Windows. By default, typelist is empty. If able to, the File constructor opens the file specified by filename, provided it is one of the types in typelist.
	</p>

	<jsproperty_list name="File">
	    <jsproperty name="access" get="1" set="1" type="string" default="read" >
	        <description>
	            File access permissions: "read", "write", or "readwrite". By default, this value is "read".
	        </description>
	    </jsproperty>

	    <jsproperty name="byteorder" get="1" set="1" type="string" default="native" >
	        <description>
	            The assumed file byteorder (endianness): "big", "little", or "native". By default, this value is "native".
	        </description>
	    </jsproperty>

	    <jsproperty name="eof" get="1" set="1" type="number" default="0">
	        <description>
	            The location of the end of file, in bytes.
	        </description>
	    </jsproperty>

	    <jsproperty name="filename" get="1" set="1" type="string">
	        <description>
	            The current filename.
	        </description>
	    </jsproperty>

	    <jsproperty name="filetype" get="1" set="1" type="string">
	        <description>
	            The four-character code associated. See <link type="vignette" module="js" name="filetypes">Filetypes Recognized in Max</link> for possible values.
	        </description>
	    </jsproperty>

	    <jsproperty name="foldername" get="1" set="0" type="string">
	        <description>
	        	The absolute path to parent folder.
	        </description>
	    </jsproperty>

	    <jsproperty name="isopen" get="1" set="0" type="Boolean">
	        <description>
	        	Return a true/false indicating if the File constructor is successful in finding and opening the file.
	        </description>
	    </jsproperty>

	    <jsproperty name="linebreak" get="1" set="1" type="string" default="native">
	        <description>
			The line break convention to use when writing lines: "dos", "mac", "unix", or "native". By default, this value is "native".
	        </description>
	    </jsproperty>

	    <jsproperty name="position" get="1" set="1" type="number">
	        <description>
	        	The current file position, in bytes.
	        </description>
	    </jsproperty>

	    <jsproperty name="typelist" get="1" set="1" type="array" default="empty array">
	        <description>
	        	An array file type codes to filter by when opening a file. By default, this is the empty array.
	        </description>
	    </jsproperty>

	</jsproperty_list>

	<jsmethod_list name="File">

		<jsmethod name="open">
			<arglist>
				<arg name="filename" type="symbol" />
			</arglist>
			<description>
				Opens the file specified by the filename argument. If no argument is specified, it will open the last opened file.
			</description>
		</jsmethod>

		<jsmethod name="close">
			<arglist>
				<arg name="string" type="symbol" />
			</arglist>
			<description>
				Closes the currently open file.
			</description>
		</jsmethod>

		<jsmethod name="writeline">
			<arglist>
				<arg name="string" type="symbol" />
			</arglist>
			<description>
				Writes the characters contained in the string argument as characters to the file, starting at the current file position, and inserts a line break appropriate to the linebreak property. The file position is updated accordingly.
			</description>
		</jsmethod>

		<jsmethod name="readline"> (<i>maximum_count</i>)
			<arglist>
				<arg name="maximum count" type="number" />
			</arglist>
			<description>
				Reads and returns a string containing up to maximum_count characters or up to the first line break as read from the file, starting at the current file position. The file position is updated accordingly.
			</description>
		</jsmethod>

		<jsmethod name="writestring"> (<i>string</i>)
			<arglist>
				<arg name="string" type="symbol" />
			</arglist>
			<description>
				Writes the characters contained in the string argument as characters to the file, starting at the current file position. Unlike writeline(), no line break is inserted. The file position is updated accordingly.
			</description>
		</jsmethod>

		<jsmethod name="readstring"> (<i>char_count</i>)
			<arglist>
					<arg name="char count" type="number" />
			</arglist>
			<description>
				Reads and returns a string containing up to char_count characters as read from the file, starting at the current file position. Unlike readline(), line breaks are not considered. The file position is updated accordingly.
			</description>
		</jsmethod>

		<jsmethod name="writebytes"> (<i>byte_array</i>)
			<arglist>
					<arg name="byte array" type="array" />
			</arglist>
			<description>
				Writes the numbers contained in the byte_array argument as bytes to the file, starting at the current file position. The file position is updated accordingly.
			</description>
		</jsmethod>

		<jsmethod name="readbytes"> (<i>byte_count</i>)
			<arglist>
					<arg name="byte count" type="number" />
			</arglist>
			<description>
				Reads and returns an array containing up to byte_count numbers, read as bytes from the file, starting at the current file position. The file position is updated accordingly.
			</description>
		</jsmethod>

		<jsmethod name="writechars"> (<i>char_array</i>)
			<arglist>
					<arg name="char array" type="array" />
			</arglist>
			<description>
				Writes the single character strings contained in the char_array argument as characters to the file, starting at the current file position.  The file position is updated accordingly.
			</description>
		</jsmethod>

		<jsmethod name="readchars"> (<i>char_count</i>)
			<arglist>
					<arg name="char count" type="number" />
			</arglist>
			<description>
				Reads and returns an array containing the single character strings, read as characters from the file, starting at the current file position. The file position is updated accordingly.
			</description>
		</jsmethod>

		<jsmethod name="writeint16"> (<i>int16_array</i>)
			<arglist>
					<arg name="int16 array" type="array" />
			</arglist>
			<description>
				Writes the numbers contained in the int16_array argument as signed 16-bit integers to the file, starting at the current file position. The byteorder property is taken into account when writing these values. The file position is updated accordingly.
			</description>
		</jsmethod>

		<jsmethod name="readint16"> (<i>int16_count</i>)
			<arglist>
					<arg name="int16 count" type="number" />
			</arglist>
			<description>
				Reads and returns an array containing the numbers read as signed 16-bit integers from the file starting at the current file position. The byteorder property is taken into account when reading these values. The file position is updated accordingly.
			</description>
		</jsmethod>

		<jsmethod name="writeint32"> (<i>int32_array</i>)
			<arglist>
					<arg name="int32 array" type="array" />
			</arglist>
			<description>
				Writes the numbers contained in the int32_array argument as signed 32-bit integers to the file, starting at the current file position. The byteorder property is taken into account when writing these values. The file position is updated accordingly.
			</description>
		</jsmethod>

		<jsmethod name="readint32"> (<i>int32_count</i>)
			<arglist>
					<arg name="int32 count" type="number" />
			</arglist>
			<description>
				Reads and returns an array containing the numbers read as signed 32-bit integers from the file starting at the current file position. The byteorder property is taken into account when reading these values. The file position is updated accordingly.
			</description>
		</jsmethod>

		<jsmethod name="writefloat32"> (<i>float32_array</i>)
			<arglist>
					<arg name="float32 array" type="array" />
			</arglist>
			<description>
				Writes the numbers contained in the float32_array argument as 32-bit floating point numbers to the file, starting at the current file position. The byteorder property is taken into account when writing these values. The file position is updated accordingly.
			</description>
		</jsmethod>

		<jsmethod name="readfloat32"> (<i>float32_count</i>)
			<arglist>
					<arg name="float32 cou t" type="number" />
			</arglist>
			<description>
				Reads and returns an array containing the numbers read as 32-bit floating point numbers from the file starting at the current file position. The byteorder property is taken into account when reading these values. The file position is updated accordingly.
			</description>
		</jsmethod>

		<jsmethod name="writefloat64"> (<i>float64_array</i>)
			<arglist>
					<arg name="float64 array" type="array" />
			</arglist>
			<description>
				Writes the numbers contained in the float64_array argument as 64-bit floating point numbers to the file, starting at the current file position. The byteorder property is taken into account when writing these values. The file position is updated accordingly.
			</description>
		</jsmethod>

		<jsmethod name="readfloat64"> (<i>float64_count</i>)
			<arglist>
					<arg name="float64 count" type="number" />
			</arglist>
			<description>
				Reads and returns an array containing the numbers read as 64-bit floating point numbers from the file starting at the current file position. The byteorder property is taken into account when reading these values. The file position is updated accordingly.
			</description>
		</jsmethod>
	</jsmethod_list>

</vignette>
