I have a file and want to split the file line by line. But I do not want to create a new file each time. just store every line in an Array. the .split() method is exactly what I want but it can't be used for files.
import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;
class Read{
public static void main(String args[])
{
try{
File datei = new File("file.txt");
Scanner myReader = new Scanner(datei);
String[] splitDatei = datei.split(System.lineSeparator());
myReader.close();
}catch(FileNotFoundException e){
System.out.println("");
e.printStackTrace();
}
}
}