Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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());
- }
Advertisement
Add Comment
Please, Sign In to add comment