无法在文件资源管理器中找到存储在设备内部存储上的文件

时间:2011-04-19 11:22:08

标签: android file-io data-storage

我使用以下代码将文件存储在设备上运行的应用程序中的内部存储上。

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_structure / files / samplefile.txt”)。我发现内部数据文件夹为空。出了什么问题?

我想读取该文件并获取数据以提供另一个用python编写的应用程序。有可能吗?

P.S:我正在设备上测试应用程序,而不是在模拟器上测试。

1 个答案:

答案 0 :(得分:2)

在进一步研究中,我发现只有在使用模拟器时,才能在文件资源管理器中看到存储在内部存储上的文件。所以看起来我不得不求助于外部存储。