简体   繁体   English

从Android上的根文件夹读取文件

[英]Read file from root folder on Android

My Android application needs to read a CSV file which is copied to the root directory on the device (device is NOT rooted so I guess it's not the real root directory, just the directory you see when opening the device in Windows explorer). 我的Android应用程序需要读取一个CSV文件,该文件已复制到设备的根目录中(设备未植根,因此我猜它不是真正的根目录,只是在Windows资源管理器中打开设备时看到的目录)。

I wonder if this is possible? 我想知道这是否可能?

When I do this: 当我这样做时:

File file = new File("/data.csv");

if (file.exists()) {
    System.out.println("File exists!");
} else {
    System.out.println("File does NOT exist");
}

I get: "File does NOT exist" 我得到:“文件不存在”

Try this: 尝试这个:
File file = new File(Environment.getExternalStorageDirectory()+ "/data.csv");
Make sure you include the proper READ permissions(depending on the API level you are targeting) in your AndroidManifest.xml 确保在AndroidManifest.xml中包含适当的读取权限(取决于您定位的API级别)

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

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