A newer version of Max is available. Click here to access the latest version of this document.
The File Object
The File object provides a means of reading and writing files from Javasccript.
File Constructor
  f = new File(filename, access, typelist);
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.
File Properties
access (String, get/set)
File access permissions: "read", "write", or "readwrite". By default, this value is "read".
byteorder (String, get/set)
The assumed file byteorder (endianness): "big", "little", or "native". By default, this value is "native".
eof (Number, get/set)
The location of the end of file, in bytes.
filename (String, get/set)
The current filename.
filetype (String, get/set)
The four-character code associated. See c74:/init/max-fileformats.txt for possible values.
foldername (String, get)
The absolute path to parent folder.
isopen (Boolean, get)
Is file open? A useful test to determine if the File constructor was successful in finding and opening the file.
linebreak (String, get/set)
The line break convention to use when writing lines: "dos", "mac", "unix", or "native". By default, this value is "native".
position (Number, get/set)
The current file position, in bytes.
typelist (Array, get/set)
An array file type codes to filter by when opening a file. By default, this is the empty array.
File Methods
open (filename)
Opens the file specified by the filename argument. If no argument is specified, it will open the last opened file.
close ()
Closes the currently open file.
writeline (string)
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.
readline (maximum_count)
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.
writestring (string)
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.
readstring (char_count)
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.
writebytes (byte_array)
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.
readbytes (byte_count)
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.
writechars (char_array)
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.
readchars (char_count)
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.
writeint16 (int16_array)
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.
readint16 (int16_count)
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.
writeint32 (int32_array)
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.
readint32 (int32_count)
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.
writefloat32 (float32_array)
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.
readfloat32 (float32_count)
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.
writefloat64 (float64_array)
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.
readfloat64 (float64_count)
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.