java - My program isn't reading the file as it's supposed to be -


i'm trying make int value, goes counter every second, when close program down, save value .txt file, , then, should, when start program again, read int value file, , continue value again, however, saving correctly, makes file, when startup program again, start @ 1 again, , not @ value saved in .txt file.

the int value:

    public int points; 

the getter , setter, located in mrstan.class

    public int getpoints(){     return points; }  public void setpoints( int points ){     this.points = points; } 

how i'm reading file:

        mrstanreadfile r = new mrstanreadfile();     r.openfile();     r.readfile();     r.closefile(); 

my readfile class:

public class mrstanreadfile {  private scanner x; mrstan = new mrstan();  public void openfile(){     try{         x = new scanner(new file("d:/mrstan/text.txt"));     }catch(exception ex){         system.out.println("could not find text.txt");     } }  public void readfile(){     while(x.hasnext()){         string p = x.next();         int pointset = integer.parseint(p);         a.setpoints(pointset);     } }  public void closefile(){     x.close(); } 

}

other places int used:

todotask:

    public mrstan(){     timer.schedule(new todotask(), 0, 1 * 1000); }  class todotask extends timertask{     public void run(){           points++;         repaint();     } }  private timer timer = new timer(); 

and

        g.drawstring("points: " + points, 75, 83); 

okay, @ readfile method, see string, p, that's string in text file. convert string int, using integer.parseint(), then, set int value converted pointset value, isn't changing, how program work start number set in .txt file?

  1. did check output "could not find text.txt"?
  2. add system.out.println("read: "+ pointset); right after int pointset = integer.parseint(p);
  3. make sure don't have this.points = 0; anywhere else.
  4. you defining mrstan = new mrstan(); inside mrstanreadfile. sure it's same object 1 use in class todotask?

Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -