Как получить доступ к строке в файле по позиции в Java
У меня есть текстовый файл со следующим содержанием:
one
two
three
four
Я хочу получить доступ к строке "три" по его положению в текстовом файле в Java. Я нашел концепцию подстроки в Google, но не смог ее использовать.
пока я могу прочитать содержимое файла:}
import java.io.*;
class FileRead
{
public static void main(String args[])
{
try{
// Open the file that is the first
// command line parameter
FileInputStream fstream = new FileInputStream("textfile.txt");
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
//Read File Line By Line
while ((strLine = br.readLine()) != null) {
// Print the content on the console
System.out.println (strLine);
}
//Close the input stream
in.close();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
Я хочу применить концепцию подстроки к файлу. Он запрашивает позицию и отображает строку.
String Str = new String("Welcome to Tutorialspoint.com");
System.out.println(Str.substring(10, 15) );