在文件资源管理器上找不到设备内部存储中存储的文件
我使用以下代码将文件存储在设备上运行的应用程序的内部存储中。
private void writeToFile(String s){
try { // catches IOException below
FileOutputStream fOut = openFileOutput("samplefile.txt",
MODE_WORLD_READABLE);
OutputStreamWriter osw = new OutputStreamWriter(fOut);
osw.write(s);
osw.flush();
osw.close();
FileInputStream fIn = openFileInput("samplefile.txt");
InputStreamReader isr = new InputStreamReader(fIn);
char[] inputBuffer = new char[s.length()];
isr.read(inputBuffer);
String readString = new String(inputBuffer);
Log.i("String", readString);
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
logcat显示文件写入正确。但是,当尝试使用 Eclipse 上的 FileExplorer 访问设备上的文件时,在应有的位置看不到该文件(“/data/data/your_project_package_struct/files/samplefile.txt”)。我发现内部数据文件夹为空。出了什么问题?
我想读取该文件并获取数据以提供另一个用 python 编写的应用程序。是否可以?
PS:我正在设备上而不是模拟器上测试应用程序。
I used the following code to store the file on Internal Storage in Application run on a device.
private void writeToFile(String s){
try { // catches IOException below
FileOutputStream fOut = openFileOutput("samplefile.txt",
MODE_WORLD_READABLE);
OutputStreamWriter osw = new OutputStreamWriter(fOut);
osw.write(s);
osw.flush();
osw.close();
FileInputStream fIn = openFileInput("samplefile.txt");
InputStreamReader isr = new InputStreamReader(fIn);
char[] inputBuffer = new char[s.length()];
isr.read(inputBuffer);
String readString = new String(inputBuffer);
Log.i("String", readString);
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
The logcat shows that the file is correctly written. But while trying to access the file on the device using FileExplorer on Eclipse the file isn't seen where it should be ("/data/data/your_project_package_structure/files/samplefile.txt"). I find the inner data folder as empty. What went wrong?
I want to read that file and get the data to feed another application written in python. Is it possible?
P.S: I am testing the application on a device and not on emulator.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
经过进一步研究,我发现存储在内部存储上的文件只有在使用模拟器时才能在文件资源管理器中看到。所以看起来我必须求助于外部存储。
On further research, I found that the files stored on the internal storage can be seen in file explorer only while using the emulator. So looks like I have to resort to external storage.