public String readFromFile() { String ret = ""; try { InputStream inputStream = context.openFileInput("locations.json"); if (inputStream != null) { InputStreamReader inputStreamReader = new InputStreamReader(inputStream); BufferedReader bufferedReader = new BufferedReader(inputStreamReader); String receiveString = ""; StringBuilder stringBuilder = new StringBuilder(); while ((receiveString = bufferedReader.readLine()) != null) { stringBuilder.append(receiveString); } inputStream.close(); ret = stringBuilder.toString(); } } catch (FileNotFoundException ex) { Log.e("login activity", "File not found: " + ex.toString()); } catch (IOException ex) { Log.e("login activity", "Can not read file: " + ex.toString()); } return ret; }
public synchronized void writeProgress(int current_file, int total_files) { try { DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(resume_file, false))); out.writeInt(current_file); out.writeInt(total_files); out.flush(); out.close(); } catch (FileNotFoundException e) { e.printStackTrace(); Log.e(TAG, "writeProgress resume.txt not found."); } catch (IOException ex) { Log.e(TAG, "Unable to create resume.txt."); } }