java.io.FileNotFoundException: Monsters.txt (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at java.io.FileInputStream.<init>(FileInputStream.java:93)
at java.io.FileReader.<init>(FileReader.java:58)
at MonsterApp.main(MonsterApp.java:28)
This is the error that i am receiving while running my application.. I cant seem to fix the code. From looking at this what would be the most likely to happen error.
This is the code from the app that im running
__ public class MonsterApp {
//A list of all monsters read in.
private static ArrayList<Monster> monsters = new ArrayList<Monster>();
/**
* The main method
* @param args
*/
public static void main(String[] args) {
//Try for IOExceptions -- called when file cannot be found
try {
/* REQUIREMENT : FILE INPUT */
//Connect to the monsters.txt file
BufferedReader br = new BufferedReader(new FileReader("Monsters.txt"));
String line = "";
//Read in each line
while((line = br.readLine()) != null) {
//Split the line
String[] parts = line.split(",");
//Try to create monsters from the file details
try {
//Swtich which kind of monster it is
switch(parts[0]) {
case "Chimera":
/* REQUIREMENT : POLYMORPHISM */
//Add chimera to monster list
monsters.add(new Chimera(Monster.SIZE.indexOf(parts[1]), Integer.parseInt(parts[2]), Integer.parseInt(parts[3]),
parts[4], Integer.parseInt(parts[5])));
break;
case "Hydra":
/* REQUIREMENT : POLYMORPHISM */
//Add hydra to monster list
monsters.add(new Hydra(Monster.SIZE.indexOf(parts[1]), Integer.parseInt(parts[2]), Integer.parseInt(parts[3]),
parts[4], Integer.parseInt(parts[5]), new Toy(parts[6], parts[7])));
break;
}
} catch (MonsterException ex) {
//Something is wrong with the monster, output the message
System.out.println(ex.getMessage());
}
}
//Loop through all the monsters
for(Monster mon : monsters) {
//Output the toString result of each monster
System.out.println(mon.toString());
//Call the scare method
mon.scare();
//Call the sleep method
mon.sleep();
}
//Close the file
br.close();
//Open the runcount file
BufferedReader br2 = new BufferedReader(new FileReader("runcount.txt"));
//Read the number of runs
int count = Integer.parseInt(br2.readLine());
//Close the file
br2.close();
//Get the file
File file = new File("runcount.txt");
//Open for writing
PrintWriter pw = new PrintWriter(file);
//Increment the count
count++;
/* REQUIREMENT : FILE OUTPUT */
//Output to the file
pw.println(count);
//Close the file
pw.close();
//Output the run count information
System.out.println("\nThis program has been run " + count + " times");
} catch (IOException e) {
//A file reading/writing error has occurred.
e.printStackTrace();
}
}
}