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] (default: read)
File access permissions: "read", "write", or "readwrite". By default, this value is "read".
byteorder [string] (default: native)
The assumed file byteorder (endianness): "big", "little", or "native". By default, this value is "native".
eof [number] (default: 0)
The location of the end of file, in bytes.
filename [string]
The current filename.
filetype [string]
The four-character code associated. See Filetypes Recognized in Max for possible values.
foldername [string]
The absolute path to parent folder.
isopen [Boolean]
Return a true/false indicating if the File constructor is successful in finding and opening the file.
linebreak [string] (default: native)
The line break convention to use when writing lines: "dos", "mac", "unix", or "native". By default, this value is "native".
position [number]
The current file position, in bytes.
typelist [array] (default: empty array)
An array file type codes to filter by when opening a file. By default, this is the empty array.
File Methods
open
Arguments
Opens the file specified by the filename argument. If no argument is specified, it will open the last opened file.
close
Arguments
Closes the currently open file.
writeline
Arguments
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
Arguments
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. The default maximum count value is 512. This can be increased by specifying a new maximum count as the argument.
writestring
Arguments
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
Arguments
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
Arguments
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
Arguments
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
Arguments
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
Arguments
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
Arguments
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
Arguments
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
Arguments
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
Arguments
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
Arguments
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
Arguments
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
Arguments
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
Arguments
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.
See Also
Name | Description |
---|---|
JavaScript Usage | JavaScript Usage |