For small files:
String line32 = Files.readAllLines(Paths.get("file.txt")).get(32)
For large files:
try (Stream<String> lines = Files.lines(Paths.get("file.txt"))) {
line32 = lines.skip(31).findFirst().get();
}
More Related Contents:
- How can I read a large text file line by line using Java?
- getResourceAsStream() vs FileInputStream
- Java: How to read a text file
- java.io.FileNotFoundException: the system cannot find the file specified
- Check if file is already open
- How do you determine the ideal buffer size when using FileInputStream?
- Delete directories recursively in Java
- getResourceAsStream returns null
- What is simplest way to read a file into String? [duplicate]
- Inserting text into an existing file via Java
- How to Write text file Java
- How to create a file in a directory in java?
- Java FileOutputStream Create File if not exists
- How to read a file from a certain offset in Java?
- Java: Path vs File
- How do I find the last modified file in a directory in Java?
- File Write – PrintStream append
- Modify the content of a file using Java
- How to save a BufferedImage as a File
- Where to put a textfile I want to use in eclipse?
- Java BufferedReader back to the top of a text file?
- GZIPInputStream reading line by line
- How to discover a File’s creation time with Java?
- Java replace specific string in text file
- Prepend lines to file in Java
- In Java, what is the default location for newly created files?
- SwingWorker ProgressBar
- Alternative to File.exists() in Java
- Does collect operation on Stream close the stream and underlying resources?
- Using reflection to change static final File.separatorChar for unit testing?