|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.neu.ccs.gui.TextFileIO
Class TextFileIO contains methods
to read an entire text file into a string and
to save a string as the content of a text file.
The basic methods use file dialogs. The most complex methods assume a File object has been defined and associated with a text file and then work with that object.
An instance retains information about the extension, file filter, and most recent directory visited by its file chooser internal object.
See also:
FileUtilities
in package edu.neu.ccs.utilFileExtensionFilter
in package edu.neu.ccs.utilTextTools
in package edu.neu.ccs.util
| Field Summary | |
protected String |
extension
The file extension to filter files. |
protected JFileChooser |
filechooser
The file chooser used for file I/O by this object. |
protected File |
home
Initialization for home directory as directory ".". |
protected FileExtensionFilter |
textFileFilter
The file filter for file I/O. |
| Constructor Summary | |
TextFileIO()
The constructor that uses no file extension and therefore may read or save any text file using file dialogs. |
|
TextFileIO(String extension)
The constructor that can read or save text files that may be filtered using the optional file extension to filter the files shown in the file dialogs. |
|
| Method Summary | |
String |
readDataFromFile()
Opens a file dialog to get the file name of a text file and then reads all data into a String that is returned. |
String |
readDataFromFile(boolean displayErrorDialogs)
Opens a file dialog to get the file name of a text file and then reads all data into a String that is returned. |
String |
readDataFromFile(File source,
boolean displayErrorDialogs)
Reads the text data from the given source text file and returns that data in a String. |
boolean |
saveDataToFile(File target,
String data,
boolean displayErrorDialogs)
Saves the given text data to the file. |
boolean |
saveDataToFile(String data)
Opens a file dialog to get the file name of a file and then saves the given text data to the file. |
boolean |
saveDataToFile(String data,
boolean displayErrorDialogs)
Opens a file dialog to get the file name of a file and then saves the given text data to the file. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
protected String extension
protected FileExtensionFilter textFileFilter
protected File home
protected JFileChooser filechooser
| Constructor Detail |
public TextFileIO()
The constructor that uses no file extension and therefore may read or save any text file using file dialogs.
public TextFileIO(String extension)
The constructor that can read or save text files that may be filtered using the optional file extension to filter the files shown in the file dialogs.
Uses no file extension and no file filter if the
given extension is null.
The extension, if supplied, should not contain a period.
extension - the optional file extension| Method Detail |
public String readDataFromFile()
Opens a file dialog to get the file name of a text file and then reads all data into a String that is returned.
Displays error dialogs.
Returns null if an errors occur.
nullpublic String readDataFromFile(boolean displayErrorDialogs)
Opens a file dialog to get the file name of a text file and then reads all data into a String that is returned.
Displays error dialogs if the last parameter is set to true.
Returns null if an errors occur.
null
public String readDataFromFile(File source,
boolean displayErrorDialogs)
Reads the text data from the given source text file and returns that data in a String.
Displays error dialogs if the last parameter is set to true.
Returns null if an errors occur.
source - the data sourcedisplayErrorDialogs - if true display error dialogs
nullpublic boolean saveDataToFile(String data)
Opens a file dialog to get the file name of a file and then saves the given text data to the file.
Displays error dialogs.
Does no save if any errors occur.
data - the data to save
public boolean saveDataToFile(String data,
boolean displayErrorDialogs)
Opens a file dialog to get the file name of a file and then saves the given text data to the file.
Displays error dialogs if the last parameter is set to true.
Does no save if any errors occur.
data - the data to savedisplayErrorDialogs - if true display error dialogs
public boolean saveDataToFile(File target,
String data,
boolean displayErrorDialogs)
Saves the given text data to the file.
Displays error dialogs if the last parameter is set to true.
Does no save if any errors occur.
target - the target filedata - the data to savedisplayErrorDialogs - if true display error dialogs
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||