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:
...which gives me this error message:
After inputting what it should have saved into the save file ("37\n39\n38\n4 0\n"), here is the code I made:
...which gives me this as output:
(There should be a zero on line 4, but I don't know why there isn't.)
What am I doing wrong? Please help!
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);
}
}
Code:
java.io.UnsupportedEncodingException: 37 39 38 40
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);
}
}
Code:
7 9 8 0
What am I doing wrong? Please help!