This method opens the file that is encapsulated by the File object.
C language programmers will be immediately familiar with this method. It behaves very similarly to the fopen() call in the ANSI C language libraries. The difference is that this method lacks a filename argument which is moved to the constructor function which is called separately.
The following flag values can be used with this method:
Flag | Description |
r | Opens the file for reading |
r+ | Opens the file for reading and writing |
w | Opens the file for writing |
w+ | Opens the file for writing and reading |
a | Opens the file for appending |
a+ | Opens the file for reading and appending |
br | Opens a Windows binary file for reading |
br+ | Opens a Windows binary file for reading and writing |
bw | Open a Windows binary file for writing |
bw+ | Opens a Windows binary file for writing and reading |
ba | Opens a Windows binary file for appending |
ba+ | Opens a Windows binary file for reading and appending |
If you are using this in a server-side application (within NES), you should make sure the project locking is activated to avoid file corruption happening if there are multiple simultaneous accesses to the file.
<SERVER> // Example file create, open and write taken from // Wrox Professional JavaScript myFile = new File("file.txt"); myFile.open("a"); myFile.writeln("Append this line to the file."); myFile.close(); </SERVER>
Prev | Home | Next |
File.getPosition() | Up | File.prototype |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |