Class Information
Package: com.onepg.util
Class Name: TxtReader
Description
Text reader class.
- Wrapper class for file reader
BufferedReader. - Declares in try clause (try-with-resources statement).
[Example]
try (final TxtReader tr = new TxtReader(filePath, ValUtil.UTF8);) {
// Skips header row
tr.skip();
for (final String line : tr) {
: Omitted
}
}
Method List
iterator
public Iterator<String> iterator()
Creates iterator.
Return Value
Iterator<String> - Read row iterator
close
public void close()
Closes file.
getReadedCount
public int getReadedCount()
Gets read row count.
- Returns the count read by the iterator.
Return Value
int - Read row count
isReadedEndRow
public boolean isReadedEndRow()
Checks if last row has been read.
Return Value
boolean - true if last row has been read
skip
public boolean skip()
Skips one row.
Return Value
boolean - false if there are insufficient rows
See Also
skip
public boolean skip(int count)
Skips rows.
- Skips rows such as header rows.
- Does not result in an error even if the skip row count is greater than the file rows, and the return value becomes
false. - Read row count is not counted up.
Parameters
| Name | Type | Description |
|---|---|---|
count |
int |
Skip row count |
Return Value
boolean - false if there are insufficient rows
getFirstLine
public String getFirstLine()
Gets first row.
- Gets the first row of the file.
- Read row count is counted up after retrieval.
- Returns
nullin the following cases- File is already closed.
- File is empty (zero rows), or has already reached the last row.
- An exception is thrown if any rows have already been read.
Return Value
String - First row string
hasNext
public boolean hasNext()
Checks next row.
- Closes file reader if next row does not exist in case try clause was not used.
- Does not recheck on consecutive hasNext() calls.
Return Value
boolean - true if next row exists
next
public String next()
Gets next row.
Return Value
String - Row