Muszę odczytać duży plik tekstowy o wielkości około 5-6 GB linia po linii przy użyciu Javy.
Jak mogę to zrobić szybko?
Spójrz na ten blog:
Rozmiar bufora może być określony, lub można użyć domyślnego rozmiaru. domyślny jest wystarczająco duży dla większości celów.
// Open the file
FileInputStream fstream = new FileInputStream("textfile.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
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
fstream.close();
Musisz użyć metody readLine()
w class BufferedReader
.
Stwórz nowy obiekt z tej klasy, wykonaj na nim tę metodę i zapisz ją do łańcucha.