Previously used this code:

public void read(View vieww){ try { FileInputStream fileInputStream = openFileInput("save.txt"); InputStreamReader streamReader = new InputStreamReader(fileInputStream); BufferedReader bufferedReader = new BufferedReader(streamReader); StringBuffer stringBuffer = new StringBuffer(); String lines; while ((lines = bufferedReader.readLine())!=null){ stringBuffer.append(lines + "\n"); } FROM_N = stringBuffer.toString(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } public void write(View view){ try { FileOutputStream fileOutputStream = openFileOutput("save.txt", MODE_PRIVATE); fileOutputStream.write(posts.getBytes()); fileOutputStream.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } 

how to call his / his counterparts in service?

  • Do not quite understand what the problem is? it seems the code is normal. And in general what to cause? Methods read and write? - Ula La
  • The problem is that when you write (call these methods) from the service, the application crashes - CrazyProgrammist
  • Well, you show an error, at least the first line that crashes. Most likely the path to the file is not correctly specified. And another tip: use try-with-resources or try-finally to close the threads that have worked and will no longer be called. - Ula La
  • Here is the error from the emulator: 12-23 10: 28: 29.987 3294-3294 /? E / libprocessgroup: unsuccessful file system / acct / uid_10059: Read-only file system - CrazyProgrammist
  • so, well, everything is clear. Because Android is based on linux, it has file permissions. For example, in your case, files are only allowed to read, but you also need to write. Call the command line on your emulator, log in as root, although it may already be root, in any case there must be a # at the end. And enter this mount -o rw, remount / system. As in your emulator, call the command line and log in as root, I unfortunately do not know. Try google or look at the developer site - Ula La

0