我在做一个项目。为了从文件中获取不同的输入,我需要一次又一次地(不断地)读取我的文件。在我的代码读取文件一次后,在运行时,我更改了内容,但无法看到新内容。我的代码在这里:
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();