java - I need to use a file to update/get High Score information -
Please help me try to access the program called "highscore.txt", then:
1: Write a new number in the file2: Get the lowest value list of numbers in the file
Please post code if you know how.
*** NOTE: I am new to Java, so I hardly know how to use the file ***
Edit:
I got a code that I should believe that should work, but when I run the program it says
the exception "main" java.util .InputMismatchException at java.util.Scanner.throwFor (Scanner.java:864) at java.util.Scanner.next (Scanner.java1485) at java.util.Scanner.nextDouble (Scanner.java): 2413) game.game. Main (game.java: 91) Java results: 1
The line is 84 - 94, and I'm here Security code.
84: Author wr = new FileWriter ("highscore.txt"); 85: Write. (Effort); 86: wr.close (); 87: Low = tries; 88: File file = new file ("HighType TX"); 89: Scanner inputfile = new scanner (file); 90: While (inputFile.hasNext ()) {91: numb = inputFile.nextDouble (); 92: If (numbed; minimum; minimum) minimum = number; 93:} 94: inputfile.close (); Edit: I have an error to do some work and it is that it just puts a random Unicode symbol in the text file. The code for that part is:
Try {int content = tries; File file = new file ("high quality TX"); // If the file does not exist, then to create it (! File.exists ()) {file.createNewFile (); } FileWriter fw = new FileWriter (file.getAbsoluteFile ()); Buffett Vitter BW = New Baffed Vitter (FW); Bw.write (content); Bw.close (); } Hold (IOException e) {e.printStackTrace (); } Writer wr = New FileWriter ("highscore.txt"); Wr.write (tries); Wr.close (); Low = effort; File file = new file ("high quality TX"); Scanner inputfile = new scanner (file); While (inputFile.hasNextInt ()) {numb = inputFile.nextInt (); If (numbed and up) minimum = numb; }
File:
32 12 7 9 18 66 13 17 91
Try it ..
int tries = 8; // write the file {int content = tries; File file = new file ("high quality TX"); // If the file does not exist, then to create it (! File.exists ()) {file.createNewFile (); } PrintWriter pw = new PrintWriter (new FileWriter (file, true)); Pw.println (content); Pw.close (); / * * Fwitter FW = new firator (file. GateAssociateFile ()); * Buffed Vitter BW = New Baffed Water (FW); Bw.write (content); * Bw.close (); Grip (IOE EXPRESS E) {E.PintstacksTrace (); } / * * Writer wr; Try {wr = new FileWriter ("highscore.txt"); * Wr.write (tries); Wr.close (); } Hold (Exception e) {* *} * / // File Minimum attempts to get minimum score from minimum; File file = new file ("high quality TX"); Scanner inputfile; {InputFile = Try new scanner (file); While {inputFile.hasNextInt ()} {int numb = inputFile.nextInt (); If (numbed and up) minimum = numb; } System.out.println ("lowest score:" + lowest); } Hold (FileNotFoundException e) {e.printStackTrace (); }
Comments
Post a Comment