|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--WriteFile
This class provides a set of simplified write-only text file methods that hide some of the details of file streams for new programmers.
Field Summary | |
static boolean |
APPEND
|
Constructor Summary | |
WriteFile()
Constructs a new WriteFile object and sets the file to null. |
Method Summary | |
void |
closeFile()
Closes the current WriteFile and sets the file pointer to null. |
boolean |
openFile(java.lang.String name)
Opens a new write-only text file for storing data. |
boolean |
openFile(java.lang.String name,
boolean append)
Opens a new write-only text file for appending data. |
void |
write(java.lang.Object o)
Writes a single object to a file without putting an end-of-line (EOL) character after the object. |
void |
writeLine(java.lang.Object o)
Writes a complete line of text to an open text file. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final boolean APPEND
Constructor Detail |
public WriteFile()
WriteFile wf = new WriteFile();Creates a new WriteFile object for subsequent usage (see openFile() method).
Method Detail |
public boolean openFile(java.lang.String name)
Once a WriteFile object is created (as per its constructor) it is ready for opening. Opening a file, sets the file pointer to the beginning position. Usage:
boolean success = wf.openFile("myfile.txt");
Returns: true if file is successfully opened, false otherwise.
public boolean openFile(java.lang.String name, boolean append)
Once a WriteFile object is created (as per its constructor) it is ready for opening. Opening a file, sets the file pointer to the next position where data can be written. Usage:
boolean success = wf.openFile("myfile.txt", APPEND);where APPEND is a predefined boolean value set to true.
Returns: true if file is successfully opened, false otherwise.
public void closeFile()
public void write(java.lang.Object o)
char someChar = 'N'; Character c = new Character(someChar); wf.write(c);results in a text file such as:
Some text on this line<EOL> N ^ <EOF>Where the caret represents the file marker where the next object will be written.
public void writeLine(java.lang.Object o)
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |