public class ReversedLinesFileReader extends java.lang.Object implements java.io.Closeable, IOIterable<java.lang.String>
To build an instance, use ReversedLinesFileReader.Builder.
For example:
try (ReversedLinesFileReader reader = ReversedLinesFileReader.builder()
.setPath(path)
.setBufferSize(4096)
.setCharset(StandardCharsets.UTF_8)
.get()) {
reader.forEach(line -> System.out.println(line));
}
ReversedLinesFileReader.Builder| Modifier and Type | Class and Description |
|---|---|
static class |
ReversedLinesFileReader.Builder
Builds a new
ReversedLinesFileReader. |
| Constructor and Description |
|---|
ReversedLinesFileReader(java.io.File file)
Deprecated.
|
ReversedLinesFileReader(java.io.File file,
java.nio.charset.Charset charset)
Deprecated.
|
ReversedLinesFileReader(java.io.File file,
int blockSize,
java.nio.charset.Charset charset)
Deprecated.
|
ReversedLinesFileReader(java.io.File file,
int blockSize,
java.lang.String charsetName)
Deprecated.
|
ReversedLinesFileReader(java.nio.file.Path file,
java.nio.charset.Charset charset)
Deprecated.
|
ReversedLinesFileReader(java.nio.file.Path file,
int blockSize,
java.nio.charset.Charset charset)
Deprecated.
|
ReversedLinesFileReader(java.nio.file.Path file,
int blockSize,
java.lang.String charsetName)
Deprecated.
|
| Modifier and Type | Method and Description |
|---|---|
static ReversedLinesFileReader.Builder |
builder()
Constructs a new
ReversedLinesFileReader.Builder. |
void |
close()
Closes underlying resources.
|
IOIterator<java.lang.String> |
iterator()
Like
Iterable.iterator(). |
java.lang.String |
readLine()
Returns the lines of the file from bottom to top.
|
java.util.List<java.lang.String> |
readLines(int lineCount)
Returns
lineCount lines of the file from bottom to top. |
java.lang.String |
toString(int lineCount)
Returns the last
lineCount lines of the file. |
java.lang.Iterable<java.lang.String> |
unwrap()
Unwraps this instance and returns the underlying
Iterable. |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitforEach, spliterator@Deprecated
public ReversedLinesFileReader(java.io.File file)
throws java.io.IOException
builder(), ReversedLinesFileReader.Builder, and ReversedLinesFileReader.Builder.get()default charset.file - the file to be readjava.io.IOException - if an I/O error occurs.@Deprecated
public ReversedLinesFileReader(java.io.File file,
java.nio.charset.Charset charset)
throws java.io.IOException
builder(), ReversedLinesFileReader.Builder, and ReversedLinesFileReader.Builder.get()file - the file to be readcharset - the charset to use, null uses the default Charset.java.io.IOException - if an I/O error occurs.@Deprecated
public ReversedLinesFileReader(java.io.File file,
int blockSize,
java.nio.charset.Charset charset)
throws java.io.IOException
builder(), ReversedLinesFileReader.Builder, and ReversedLinesFileReader.Builder.get()file - the file to be readblockSize - size of the internal buffer (for ideal performance this
should match with the block size of the underlying file
system).charset - the encoding of the file, null uses the default Charset.java.io.IOException - if an I/O error occurs.@Deprecated
public ReversedLinesFileReader(java.io.File file,
int blockSize,
java.lang.String charsetName)
throws java.io.IOException
builder(), ReversedLinesFileReader.Builder, and ReversedLinesFileReader.Builder.get()file - the file to be readblockSize - size of the internal buffer (for ideal performance this
should match with the block size of the underlying file
system).charsetName - the encoding of the file, null uses the default Charset.java.io.IOException - if an I/O error occursjava.nio.charset.UnsupportedCharsetException - if the encoding is not supported@Deprecated
public ReversedLinesFileReader(java.nio.file.Path file,
java.nio.charset.Charset charset)
throws java.io.IOException
builder(), ReversedLinesFileReader.Builder, and ReversedLinesFileReader.Builder.get()file - the file to be readcharset - the charset to use, null uses the default Charset.java.io.IOException - if an I/O error occurs.@Deprecated
public ReversedLinesFileReader(java.nio.file.Path file,
int blockSize,
java.nio.charset.Charset charset)
throws java.io.IOException
builder(), ReversedLinesFileReader.Builder, and ReversedLinesFileReader.Builder.get()file - the file to be readblockSize - size of the internal buffer (for ideal performance this
should match with the block size of the underlying file
system).charset - the encoding of the file, null uses the default Charset.java.io.IOException - if an I/O error occurs.@Deprecated
public ReversedLinesFileReader(java.nio.file.Path file,
int blockSize,
java.lang.String charsetName)
throws java.io.IOException
builder(), ReversedLinesFileReader.Builder, and ReversedLinesFileReader.Builder.get()file - the file to be readblockSize - size of the internal buffer (for ideal performance this
should match with the block size of the underlying file
system).charsetName - the encoding of the file, null uses the default Charset.java.io.IOException - if an I/O error occursjava.nio.charset.UnsupportedCharsetException - if the encoding is not supportedpublic static ReversedLinesFileReader.Builder builder()
ReversedLinesFileReader.Builder.ReversedLinesFileReader.Builder.public void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseablejava.io.IOException - if an I/O error occurs.public IOIterator<java.lang.String> iterator()
IOIterableIterable.iterator().iterator in interface IOIterable<java.lang.String>delegate.Iterable.iterator()public java.lang.String readLine()
throws java.io.IOException
java.io.IOException - if an I/O error occurs.public java.util.List<java.lang.String> readLines(int lineCount)
throws java.io.IOException
lineCount lines of the file from bottom to top.
If there are less than lineCount lines in the file, then that's what
you get.
Note: You can easily flip the result with Collections.reverse(List).
lineCount - How many lines to read.java.io.IOException - if an I/O error occurs.public java.lang.String toString(int lineCount)
throws java.io.IOException
lineCount lines of the file.
If there are less than lineCount lines in the file, then that's what
you get.
lineCount - How many lines to read.java.io.IOException - if an I/O error occurs.public java.lang.Iterable<java.lang.String> unwrap()
IOIterableIterable.
Implementations may not have anything to unwrap and that behavior is undefined for now.
unwrap in interface IOIterable<java.lang.String>Copyright © 2010 - 2025 Adobe. All Rights Reserved