我只是在尝试使用此代码编写的文本文件:安卓:试图保存文件
try {
File ins = new File(context.getFilesDir(), "myfile");
FileOutputStream out = new FileOutputStream(ins);
out.write(string.toString().getBytes());
out.close();
} catch (Exception e) {
e.printStackTrace();
}
我自己也尝试这样的代码:
File aux = context.getFilesDir();
String filename = "myfile";
String string = "Hello world!";
FileOutputStream outputStream;
try {
outputStream = openFileOutput(aux + filename, MODE_PRIVATE);
outputStream.write(string.getBytes());
outputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
问题:IM没有得到任何错误,但是他们都没有保存文件。我期望在找到新文件,因为content.getFilesDir()
的输出就是这样。
而且,我无法找到根/data/
文件夹,但一个/Android/data
之一,而后者的里面,有几个目录,如com.android.browser
或com.dropbox.android
,但他们没有被命名为com.example.tirengarfio.myapplication
。
您尝试/ storage/emulated/data吗?有时模拟不存在或可能事情正在存储在SD卡中,但您的文件可能在里面/存储 –
你是如何验证该文件不存在 – ligi