我有寫這個代碼,並讀取文件ZIZI.txt:如何在沒有root權限的情況下訪問寫入的文件?
//=============== Write To File ZIZI.txt ===============================================
private void writeFileToInternalStorage() {
String eol = System.getProperty("line.separator");
BufferedWriter writer = null;
try {
writer = new BufferedWriter(new OutputStreamWriter(openFileOutput(
"ZIZI.txt", MODE_WORLD_WRITEABLE)));
writer.write("This is a test1." + eol);
writer.write("This is a test2." + eol);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (writer != null) {
try {
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Toast.makeText(getBaseContext(),"OK Save", Toast.LENGTH_SHORT).show();
}
//================ Read From File ZIZI.txt ===========================================
private void readFileFromInternalStorage() {
String FF="";
String eol = System.getProperty("line.separator");
BufferedReader input = null;
try {
input = new BufferedReader(new InputStreamReader(openFileInput("ZIZI.txt")));
String line;
StringBuffer buffer = new StringBuffer();
while ((line = input.readLine()) != null) {
FF+=line+eol;
buffer.append(line + eol);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (input != null) {
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Toast.makeText(getBaseContext(),FF, Toast.LENGTH_SHORT).show();
}
我DDMS該文件中看到:\data\data\setup.myProject\files\ZIZI.txt
但我不能看到這個文件我手機(因爲我沒有root權限)
我想寫我的SD卡或從我的 手機中看到的任何文件夾中讀取。如何更改此代碼?
也許你想要一個應用程序,讓你看到所有文件夾(文件系統),包括根? – 2012-03-30 18:41:18
我只需要知道什麼改變我的代碼,我可以寫入和閱讀文件夾,我可以在手機上看到 – Gold 2012-03-30 19:00:54