private void writeToFile(int value) { String text = String.valueOf(value); try (FileOutputStream fos = context.openFileOutput(classFile, Context.MODE_PRIVATE)) { fos.write(text.getBytes()); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } public int readHighScore() { StringBuilder sb = new StringBuilder(); try (FileInputStream fis = context.openFileInput(classFile)) { InputStreamReader isr = new InputStreamReader(fis); BufferedReader br = new BufferedReader(isr); String text; while((text = br.readLine()) != null) { sb.append(text); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return Integer.parseInt(sb.toString()); }