I am trying to read questions that are listed in each line of a text file and then adding each line to an array, so that they can be called individually later on. I'm almost positive it is possible to do in Java but I am unsure how to do it.
I did figure out how to read a whole text file and setting it all to a string:
private static String readFile(String pathname) {
String line = null;
try {
BufferedReader reader = new BufferedReader(new FileReader(pathname));
while((line = reader.readLine()) != null){
System.out.println(line);
}
} catch (Exception e) {
e.printStackTrace();
}
return line;
}
Although it doesnt have much to do with this, as I mentioned this is a file that holds questions. If I get a solution to this problem I will be having another file for all the answers to the questions and I will then do the same thing for that file.
Does anyone know of a not overly complicated way to do this? If it has to be complicated then tell me that. I would like some type of example and not just links to different sites. Im not saying I will only take that though.
Thank you for your time!
P.S. I have read other questions on this topic but could not find a suitable answer and/or example for what I am trying to do in Java.
I did figure out how to read a whole text file and setting it all to a string:NO, your String will benullwhen you return it.