I'm trying to read large file(approximately 516mb), and it has 18 lines of text. I tried to write down the code myself and got an error in the first line of code while trying to read the file:
try(BufferedReader br = new BufferedReader(new FileReader("test.txt"))) {
String line;
while ((line = br.readLine()) != null) {
String fileContent = line;
}
}
Note: File exists and it's size is approximately 516mb. If there is another safer and faster method of reading from please tell me(Even if it will linebreaks). Edit: Here I tried by using Scanner, but it lasts a bit longer and then gives the same error
try(BufferedReader br = new BufferedReader(new FileReader("test.txt"))) {
Scanner scanner = new Scanner(br);
while(scanner.hasNext()){
int index = Integer.parseInt(scanner.next());
// and here do something with index
}
}
I even splitted file into 1800 lines, but nothing got fixed