so im relatively new to code,particularly to this io problems, here is my code
actually all im trying to do is just to read a file,and add each line to my existing list that named scorelist,but the problem is i dont know where to store the files because i just dropped my files on my project folders where this score.java located, is that any problem?or am i missed something from my code?
any help will be appreciated thanks!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.util.List; import java.util.ArrayList; import java.util.Collections; import java.io.*; /** * Write a description of class Score here. * * @author (your name) * @version (a version number or a date) */ public class Score extends Actor { int t = 0 ; int minute,second; int currentscore,highscore,savedscore; String TotalScore,csaved; boolean countstart = false ; GreenfootImage score; List <Integer> scorelist = new ArrayList<Integer>(); private void readfile() { BufferedReader br = null ; try { br = new BufferedReader( new FileReader( "highscore.txt" )); String r = br.readLine(); while (r != null ) { scorelist.add(Integer.parseInt(r)); } } catch (IOException ex) { ex.printStackTrace();} } } |