public class FileInput extends Object implements AutoCloseable
Modifier and Type | Field and Description |
---|---|
private static char |
COMMENT_CHAR |
private static Charset |
DEFAULT_ENCODING |
private static String |
DEFAULT_SEP |
private Pattern |
fieldSep |
private Charset |
fileEncoding |
private Path |
path |
protected BufferedReader |
reader |
Constructor and Description |
---|
FileInput(String dataFileName)
Open a handle to a file with the given name.
|
FileInput(String dataFileName,
String sep)
Open a handle to a file with the given name.
|
FileInput(String dataFileName,
String sep,
Charset encoding)
Open a handle to a file with the given name.
|
Modifier and Type | Method and Description |
---|---|
void |
close() |
FileInputIterator |
iterator()
Obtain an iterator for this input file.
|
String |
read()
Read the contents of the file into a single string object.
|
List<String> |
readLine()
Read a line from the input file, split it according to the seperator specified in the constructor and get a list
of tokens from the line.
|
String |
readNextLine()
Get the next (non-comment) line from the file.
|
private List<String> |
tokeniseLine(String line)
Split a string (a line read from a file into tokens.
|
private Path path
protected BufferedReader reader
private Pattern fieldSep
private Charset fileEncoding
private static final String DEFAULT_SEP
private static final Charset DEFAULT_ENCODING
private static final char COMMENT_CHAR
public FileInput(String dataFileName) throws IOException
dataFileName
- the name of the file.IOException
- if the resource can't be found.public FileInput(String dataFileName, String sep) throws IOException
dataFileName
- the name of the file.sep
- The single char for the separator (not a list of separator characters).IOException
- if the resource can't be found.public FileInput(String dataFileName, String sep, Charset encoding) throws IOException
dataFileName
- the name of the file.sep
- The single char for the separator (not a list of separator characters).encoding
- the encoding used in the file e.g. UTF-8.IOException
- if the resource can't be found.public final List<String> readLine() throws IOException
IOException
- if a line cannot be read, e.g if the object was closed.public final String readNextLine() throws IOException
IOException
- if a line cannot be read, e.g if the object was closed.public final String read() throws IOException
IOException
- if a line cannot be read, e.g if the object was closed.private List<String> tokeniseLine(String line)
line
- the line that is to be tokenised.public final void close()
close
in interface AutoCloseable
public final FileInputIterator iterator()
Copyright © 2015 University of Glasgow. All rights reserved.