I’m trying to compare my highscore that I saved in A file to compare with an integer. So I always will get three characters out of my file, butt if I control it it doesn’t put my new score in it.
try{
String FILENAME = "HanoiScore1File";
FileInputStream fos = openFileInput(FILENAME);
byte[] b = new byte[2];
fos.read(b);
fos.close();
Data = new String(b);
Score2 = Integer.parseInt(Data);
}catch (java.io.FileNotFoundException e) {
} catch (IOException e) {
e.printStackTrace();
}
if(Score2>Score){
try{
String FILENAME="HanoiScore1File";
Data=Integer.toString(Score);
FileOutputStream fostemp = openFileOutput(FILENAME, Context.MODE_PRIVATE);
fostemp.write(Data.getBytes());
fostemp.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
This Works but the mistake I made was
Score2 was always 0, which will never be bigger than Score, so It didn’t save the high score.