|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.townleyenterprises.io.TextFileProcessor
This class provides a pluggable mechanism for processing line-based
text files with a given character encoding. The class breaks up
the input file into lines of text. The actual processing of the
line is provided by providing an instance of LineProcessor
apropriate for the task.
An example of echoing the file to the console:
try { // create a text file processor using the default encoding TextFileProcessor fp = new TextFileProcessor("myfile.dat"); fp.processFile(new AbstractLineProcessor() { public void processLine(String line) throws Exception { super.processLine(line); System.out.println(line); } }); } catch(FileNotFoundException e) { e.printStackTrace(); }
Constructor Summary | |
TextFileProcessor(java.lang.String name)
The constructor initializes the input file using the default encoding. |
|
TextFileProcessor(java.lang.String name,
java.lang.String encoding)
The constructor initializes the input file using the specified character encoding. |
Method Summary | |
void |
processFile(LineProcessor lp)
This method is used to process the file. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public TextFileProcessor(java.lang.String name)
name
- the name of the file to processpublic TextFileProcessor(java.lang.String name, java.lang.String encoding) throws java.nio.charset.UnsupportedCharsetException
name
- the name of the file to processencoding
- the encoding of the input file
java.nio.charset.UnsupportedCharsetException
- if the encoding is not supported by the JVMMethod Detail |
public void processFile(LineProcessor lp) throws java.io.IOException, java.lang.Exception
lp
- the LineProcessor instance
java.io.IOException
- if there was an error reading the file
java.lang.Exception
- if there was an error thrown by the LineProcessor
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |