我正在开始学习将文件写入SD卡。但是,我需要一些澄清,因为我不明白为什么我在getAbsolutePath()(由Android工作室检测到)中得到错误。
public class AndroidFileIO implements FileIO {
Context context;
AssetManager assets;
String externalStoragePath;
public AndroidFileIO( Context context ) {
this.context = context;
this.assets = context.getAssets();
this.externalStoragePath = Environment.getExternalStorageState().getAbsolutePath()
+ File.separator;
}
谢谢,
答案 0 :(得分:0)
更改此
this.externalStoragePath = Environment.getExternalStorageState().getAbsolutePath()
+ File.separator;
到
this.externalStoragePath = Environment.getExternalStorageDirectory().getAbsolutePath()
+ File.separator;
更多信息@
http://developer.android.com/guide/topics/data/data-storage.html#filesExternal
public static String getExternalStorageState ()
//返回类型是字符串
Added in API level 1
Returns the current state of the primary "external" storage device
public static File getExternalStorageDirectory ()
Added in API level 1
Return the primary external storage directory
查看File
http://developer.android.com/reference/java/io/File.html#getAbsolutePath()
public String getAbsolutePath ()
Added in API level 1
Returns the absolute path of this file. An absolute path is a path that starts at a root of the file system. On Android, there is only one root: /.