I get an error - \"missing return statement\" - on line 26, which in this case is the last curly bracket in the code. I know that it literally means that I have to return somewh
If you just want to print the file as you are doing right now, change the return type to void
as follows:
public void OpenFile() throws IOException {
Otherwise, since you are just opening and reading in a text file, you might want another String
variable that you append the file's lines to and then return, as opposed to a String[]
. Maybe something like this:
public String openFile(String fileName) throws IOException {
String output = "";
FileReader fr = new FileReader(fileName);
BufferedReader br = new BufferedReader(fr);
try {
while (br.ready()) {
String line = br.readLine();
output += line + "\n";
}
} catch (IOException e) {
System.err.println("Error - IOException!");
}
return output;
}