我正嘗試從Android中的/ data分區讀取文件。我編寫了一個測試應用程序,然後在模擬器上啓動它。然後,我使用「adb push local_path_to_file/data/mydir/file1」複製/ data/mydir /下的file1。從文件系統中讀取文件
現在我想在我的應用程序下面並沒有任何反應:(
如何讀取保存在/數據的文件有什麼錯我的代碼
以下是代碼片段:??
try {
File source = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/data/pu/file1");
InputStream is = new FileInputStream(source);
String fileStr = new String(ReadBytesOfFile(is).toString);
System.out.println("file out ="+ fileStr);
is.close();
}
catch(IOException e){
Log.d("file","NOT FOUND");
}
public byte [] ReadBytesOfFile (InputStream input) throws IOException {
long length = input.available();
byte[] rbuffer = new byte[(int) length];
input.read(rbuffer);
return rbuffer;
}
我也試過了:Environment.getExternalStorageDirectory()+「/ data/pu/file1」 – user489152