繁体   English   中英

访问保存在Android设备上的内部存储的数据

[英]Accessing Data Saved to Internal Storage on Android Device

我是Android Studio的新手,经历了大量的教程。 我有一个工作加速度计,并希望将数据保存到.csv文件。 我的代码可以正常工作,因为当我使用模拟器时,我能够将带有正确数据的.csv文件导出到我的桌面并打开它。 我的AndroidManifest.xml有这两个权限

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

当我使用Astro或ES等应用程序进入我的设备上的文件浏览器并转到data/data/我甚至看不到我的包,即使该应用程序在我的手机上工作。 您是否需要执行某些操作才能将程序包显示在文件资源管理器中? 我想从手机上获取.csv的数据。

我希望有人进来

String Entry = x.getText().toString() + ", "
        + y.getText().toString() + ", " +
        z.getText().toString() + "\n";
try{
    FileOutputStream outPut = openFileOutput(FILENAME, Context.MODE_APPEND);
    outPut.write(Entry.getBytes());
    outPut.close();
}catch(Exception err){
    err.printStackTrace();
}

编辑

String dir = Environment.getExternalStorageDirectory().getAbsolutePath();
        String FILENAME = "keyboardTest.csv";
        File file = new File (dir, FILENAME)
       try {   
                FileOutputStream out = new FileOutputStream(file, true);
                out.write(Entry.getBytes());
                out.close();
            } catch (Exception err) {
                err.printStackTrace();
            }

现在我可以在手机上访问该文件

在模拟器上运行应用程序或在root设备上运行应用程序之前,您无法访问这些文件(内部/数据/数据)。

请查看更多详细信息。

编辑

您可以执行以下操作将文件保存在可访问的位置: -

/*get the path to internal storage*/
File path = Environment.getExternalStorageDirectory();
/*create the app folder and check if it exists or not*/
File curDir = new File(path.getAbsolutePath()+"/"+appName);
if(!curDir.exists()){
        curDir.mkdirs();
}
/*create the file*/
File f = new File(curDir+"/"+fileName);
f.createNewFile();
/*code to edit the file*/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM