|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectcom.marringtons.file.FileReader
This class provides simple access to read a text file that is found on one of the system paths or Zip files. A file within a specific archive can be specified with the special /#/ syntax to separate zip file from content. Use close when completed with the stream (not needed by load or readLines).
FileReader fileReader = new FileReader( "/com/fred/project/myFile.txt"); ... read from file fileReader.close(); FileReader nextReader = new FileReader( "myFile2.txt", fileReader); fileReader.close(); fileReader = nextReader; // same as... but open preferred to working the garbage collector if (fileReader.open( "myFile2.txt")) ... if (fileReader.open( "/com/fred/project/myFile2.txt")) ... if (fileReader.open( "file:///etc/hosts")) ... if (fileReader.open( "file://c:/winnt/system32/drivers/etc/hosts")) ... if (fileReader.open( "myArchive.zip/#/myFile2.txt")) ... // same as... fileReader.setArchive( "myArchive.zip"); if (fileReader.open( "myFile2.txt")) ... // or we can get a list of archive entries String[] files = fileReader.listArchive(); fileReader.setArchive( null); so can be used for non-archive again String line; while ((line = fileReader.getLine()) != null) processLine(); fileReader.close(); byte[] contents = fileReader.load(); // no close needed
| Constructor Summary | |
FileReader()
Default constructor. |
|
FileReader(String filePath)
Search for a file on all datapaths, given the absolute (to datapath) name. |
|
FileReader(String filePath,
boolean mustExist)
In some circumstances it is an error if the file does not exists. |
|
| Method Summary | |
void |
close()
Close BufferedReader object. |
String |
getClassName()
Assuming that the file is actually a Java class file, extract the class name from the file name. |
File |
getFile()
Retrieve a pointer to the underlying file. |
InputStream |
getInputStream()
Retrieve a pointer to the underlying input stream. |
BufferedReader |
getReader()
Buffered reader used internally or externally when more sophisticated reading is required. |
boolean |
isArchived()
Used if you need to know if a file exists in the file system or part of an archive. |
boolean |
isOpen()
See if the file is open. |
String[] |
listArchive()
Retrieve a full list of file entries in an archive |
byte[] |
load()
Loads the file as one chunk. |
boolean |
open(String filePath)
Search for a file on all datapaths, given the relative or absolute (to datapath) name. |
String |
readLine()
Read a line from the file, opening it if necessary. |
static String[] |
readLines(String name)
Reads the entire file and returns it in an array of lines. |
void |
setArchive(String archiveName)
Set the archive used for the next open statement. |
static void |
setZipFileCacheSize(int size)
Only ever called by Application.load() to reset the zip file cache size to overcome chicken-and-egg problem. |
int |
size()
Retrieve the size of the opened file. |
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public FileReader()
public FileReader(String filePath)
filePath - - path relative to default paths (not absolute to filesystem)
public FileReader(String filePath,
boolean mustExist)
throws FileNotFoundException
filePath - mustExist - true to throw an error if the file is not found
FileNotFoundException| Method Detail |
public boolean open(String filePath)
filePath - path relative to default paths (not absolute to filesystem). It can also
be part of a specified archive if setArchive is called first or if the path includes
/#/ to separate the archive from file path components.
public void setArchive(String archiveName)
archiveName - absolute or relative name of archive file or null for no default archive.
public String[] listArchive()
throws IOException
IOExceptionpublic BufferedReader getReader()
public boolean isOpen()
public boolean isArchived()
public void close()
public String readLine()
throws IOException
IOExceptionpublic static String[] readLines(String name)
name - of file to read
public byte[] load()
throws IOException
IOExceptionpublic InputStream getInputStream()
public File getFile()
public int size()
public static void setZipFileCacheSize(int size)
size - new size. Only used if greater than 10.public String getClassName()
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||