我正在使用android-ndk寫入文件。因此,使用本地c代碼進行文件寫入。同時在NDK中寫入和讀取文件android
它包含一些我正在使用ndk的讀數。 點擊一個按鈕即可開始寫入文件。同時我想讀取文件的內容並將它們用於顯示值的另一個線程中,因爲寫入操作可能會持續15秒,用戶將不得不等待那麼多時間才能看到結果,所以我想要顯示一個結果一旦我把它放入那個文件中。
是否可行,如果是的話,可以告訴我如何去做?
嗯,我開始用它,右NW其如何我這樣做,,
Thread thr1 = new Thread(r1);
Thread thr2 = new Thread(r2);
thr1.start();
thr2.start();
r1 = new Runnable() {
public void run() {
File sdcard= Environment.getExternalStorageDirectory();
nativeFunction(sdcard +"/readings.txt");
//takingReading=false;
readingFile = new File(sdcard +"/readings.txt");
Log.i("length of file", ""+readingFile.length());
}
};
r2 = new Runnable() {
public void run() {
try {
Thread.sleep(3000);
File sdcard= Environment.getExternalStorageDirectory();
readingFile = new File(sdcard +"/readings.txt");
Log.i("length of file", ""+readingFile.length());
} catch (InterruptedException iex) {}
}
};
nativeFunction打開
file= fopen(location,"w+");
此功能不斷寫的東西在文件約2分鐘, 但我需要不斷得到值輸入bye原生函數,所以我開始第二線程,但是當我檢查file.length()它總是0.
和wh本機功能寫入完成,然後實際文件大小。那麼如何解決這個問題呢?
我想知道可行性,無論是否可行,那麼只有我想到開始。 –