import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
public class Read_Text_File {
public static void main(String[] args) {
System.out.println(getValues());
}
public static ArrayList<String> getValues() {
FileInputStream stream = null;
try {
stream = new FileInputStream("src/resources/java_txt_file.txt");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
String strLine;
ArrayList<String> lines = new ArrayList<String>();
try {
while ((strLine = reader.readLine()) != null) {
String lastWord = strLine.substring(strLine.lastIndexOf(" ")+1);
lines.add(lastWord);
}
} catch (IOException e) {
e.printStackTrace();
}
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
return lines;
}
}
Output:
[k0LiuME5Q3, ab4454jj]
1
solved How to parse a simple text file in java