How can I load .txt file into string array?
private void FileLoader() {
try {
File file = new File("/some.txt");
Scanner sc = new Scanner(new FileInputStream(file), "Windows-1251");
//Obviously, exception
int i = 0;
while (sc.hasNextLine()) {
morphBuffer[i] = sc.nextLine();
i++;
//Obviously, exception
}
sc.close();
} catch (FileNotFoundException e) {
JOptionPane.showMessageDialog(null, "File not found: " + e);
return;
}
}
There is an issue with array's length, because I don't know how long my array will be.
Of course i saw this question, but there is not an array of string. I need it, because I have to work with whole text, also with null
strings.
How can I load a text file into string array?