So I'm making this simple zombie simulation game wherein a player is given a situation and different options to choose. Whenever they make a decision I have an object that will write a letter within a file which is a number. This number indicates their score on depending on the decision.
System.out.println("\n\t\t=================================================="); System.out.println("\t\t| |"); System.out.println("\t\t| You have been hiding inside your house for a |"); System.out.println("\t\t| few days now. Outside there are plenty of |"); System.out.println("\t\t| Zombies outside. What will you do? |"); System.out.println("\t\t| |"); System.out.println("\t\txxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); System.out.println("\t\txxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); System.out.println("\t\t|| [1] Barricade the house ||"); System.out.println("\t\t|| [2] Go outside and fight the zombies ||"); System.out.println("\t\t|| [3] Search for supply ||"); System.out.println("\t\t|| [4] Escape through the back ||"); System.out.println("\t\t=================================================="); System.out.print("\t\tWhat would it be?: "); int ans1 = keyIn.nextInt(); switch(ans1) { case 1: HomeGame.home1a(); loop = false; break; case 2: HomeGame.home1b(); loop = false; break; case 3: HomeGame.home1c(); loop = false; break; case 4: HomeGame.home1d(); loop = false; Score.addScore(); break;
This is the code for the object (This is still just a testing so everything is short)
public static void addScore() throws Exception { try{ FileWriter outFile = new FileWriter("test.txt", true); outFile.write("a"+"\r\n"); outFile.close(); } catch(Exception e) { System.out.println("Something went wrong: "+e.getMessage()); } } public static void ShowScore() { try { int count = 0; BufferedReader fileIn = new BufferedReader (new FileReader("text.txt")); String S = fileIn.readLine(); while(S!=null) count++; System.out.println("line "+count+": "+S); S = fileIn.readLine(); } catch(Exception e) { System.out.println("Something went wrong: "+e.getMessage()); } } }
The output I always get is: No such file or directory exist