The error occurs because you are trying to access fileContent
out of try catch
.
Declare the variable before it is accessible:
public class ShowDoMilhao {
public ShowDoMilhao() {
}
public static void main(String[] args) throws IOException {
String file1 = "Facil.txt";
String[] fileContent;
try {
ReadFile file = new ReadFile(file1);
fileContent = new String[file.readLines()];
fileContent = file.OpenFile();
}catch (IOException e) {
System.out.println(e.getMessage());
}
System.out.println(fileContent[0]);
}
}
Note that I made the declaration of the variable out of try catch
, otherwise it is visible only in the scope of try catch