0

I working on a project. In order to take different inputs from a file, I need to read my file again and again (constantly). After my code reading the file once, while it running, I change it content but it can not see the new content. My code is here:

Thread thread = new Thread() {

  public void run() {
    while (true) {
      try {


        AssetManager assetManager = getAssets();
        InputStream input;

        try {

          input = assetManager.open("dummy_input.txt", 0);
          //RandomAccessFile in = new RandomAccessFile("file.txt", "r")
          Log.d(TAG, "here");

          int size = input.available();

          byte[] buffer = new byte[size];
          input.read(buffer);
          input.close();

          str = new String(buffer);

          //txtFileName.setText(text);

        } catch (Exception e) {
          // TODO: handle exception
          e.printStackTrace();
        }


        Log.d(TAG, "local Thread sleeping");
        Log.d(TAG, "str3= " + str);
        Thread.sleep(1000);
      } catch (InterruptedException e) {
        Log.e(TAG, "local Thread error", e);
      }
    }
  }
};
thread.start();

0 Answers0