Saving and Loading Issues

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mathgeek314
    New Member
    • Jun 2012
    • 3

    #1

    Saving and Loading Issues

    Okay, so I have two methods, one to save selected arrow keys to a text file, and the other to load them as integers. Here's the first:

    Code:
    public void saveKeys()
    {
       String out = Integer.toString(left)+"\n"+Integer.toString(right)+"\n"+Integer.toString(up)+"\n"+Integer.toString(down)+"\n";
       try
       {
          PrintWriter save = new PrintWriter("key_selection.txt",out);
       }
       catch ( Exception e )
       {
                System.err.print(e);
       }
    }
    ...which gives me this error message:

    Code:
    java.io.UnsupportedEncodingException: 37
    39
    38
    40
    After inputting what it should have saved into the save file ("37\n39\n38\n4 0\n"), here is the code I made:

    Code:
    public void loadKeys()
    {
       try
       {
          FileInputStream fis = new FileInputStream("key_selection.txt");
          BufferedInputStream bis = new BufferedInputStream(fis);
          String in = "";
          while ( bis.read() > -1 )
          {
             in += (char)bis.read();
          }
          System.out.println(in);
       }
       catch ( Exception e )
       {
          System.err.println(e);
       }
    }
    ...which gives me this as output:

    Code:
    7
    9
    8
    0
    (There should be a zero on line 4, but I don't know why there isn't.)

    What am I doing wrong? Please help!
Working...