安卓文件读取
获取外部存储的绝对路径
return Environment.getExternalStorageDirectory().getAbsolutePath();
并且需要加上外部的读写获取权限
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
public static String getSDPath(){
File sdDir = null;
boolean sdCardExist = Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED); //判断sd卡是否存在
if (sdCardExist)
{
sdDir = Environment.getExternalStorageDirectory();//获取跟目录
}
return sdDir.toString();
}
判断外部路径是否存在,如果存在那么久获取当前的目录,并且是绝对路径