I am trying to use readFile function from Container super class but I trigger FileNotFound exception under stack. What am I missing here?
public static final List<String> readFile(String fileName) throws FileNotFoundException, IOException {
List<String> result = new ArrayList<>();
try (Scanner s = new Scanner(new File(fileName))) {
while (s.hasNextLine()) {
result.add(s.nextLine());
s.close();
}
return result;
}
}
public Stack(String fileName) throws FileNotFoundException, IOException {
stack = new ArrayList<String>();
String obj = (String) Stack.readFile(fileName).get(0);
stack.add(obj);
if(obj.startsWith("Stack"))
{
stack.add(obj.substring(4).strip());
}
}
try to read file under Stack function by using readFile function.