title: Read and Write to file in the same time
body: <p>I want to write and read from file in the same time without errors.
  For example, I will starting new Thread for writing to file from my running service.
  In my activity i will starting new Thread for reading from the same file.
  I wan't to do this synchronously. Some thing like this :</p>
  
  <ol>
  <li>To wait execution of next thread until previous finished.</li>
  <li>Next thread must not start until previous thread stops, irrespective of time consumption.</li>
  </ol>
  
  <p>My code for read and write:</p>
  
  <pre><code>public static final String ROUTE_FILE_NAME = "route.txt";
  
      public static void savePointToFile(Context context, String point) throws IOException {
  
          FileOutputStream fOut = context.openFileOutput(ROUTE_FILE_NAME, Context.MODE_APPEND);
  
          OutputStreamWriter osw = new OutputStreamWriter(fOut);
          osw.write(point);
          osw.flush();
          osw.close();
      }
  
      public static String readRouteFromFile(Context context) {
          StringBuffer fileContent = new StringBuffer(UIUtils.emptyString());
          byte[] buffer = new byte[1024];
          try {
              FileInputStream fis = context.openFileInput(ROUTE_FILE_NAME);
  
              int length;
  
              while ((length = fis.read(buffer)) != -1) {
                  fileContent.append(new String(buffer));
              }
  
          } catch (FileNotFoundException e) {
              e.printStackTrace();
          } catch (IOException e) {
              e.printStackTrace();
          }
          return fileContent.toString();
      }
  </code></pre>
  
  <p>Thanks in advance.</p>