我有这个代码用于写入和读取文件ZIZI.txt:
//=============== 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 卡或手机中可以看到的任何文件夹中写入和读取。如何更改此代码?