Logcat在memorymethod.java中的这些行中显示错误
所有与getexternalpath()
方法相关的错误,我在下面的memorymothod.java代码中给出了它。
StatFs statFs2 = new StatFs(getExternalPath());
public static double getExternalUsedStorage()
{
return Double.parseDouble(getExternalTotalMemory())-Double.parseDouble(getExternalFreeMemory());
}
以下是memorymethod.java
的一些代码:
public static String getExternalPath()
{
String sSDpath = null;
File fileCur = null;
for( String sPathCur : Arrays.asList("MicroSD", "external_SD", "sdcard1", "ext_card", "external_sd", "ext_sd", "external", "extSdCard", "externalSdCard")) // external sdcard
{
fileCur = new File( "/mnt/", sPathCur);
if( fileCur.isDirectory() && fileCur.canWrite())
{
sSDpath = fileCur.getAbsolutePath();
break;
}
if( sSDpath == null)
{
fileCur = new File( "/storage/", sPathCur);
if( fileCur.isDirectory() && fileCur.canWrite())
{
sSDpath = fileCur.getAbsolutePath();
break;
}
}
if( sSDpath == null)
{
fileCur = new File( "/storage/emulated", sPathCur);
if( fileCur.isDirectory() && fileCur.canWrite())
{
sSDpath = fileCur.getAbsolutePath();
//Log.e("path",sSDpath);
break;
}
}
fileCur = new File( "/storage/extSdCard");
return fileCur.getAbsolutePath();
}
答案 0 :(得分:0)
检查此代码
String fileName="abc.txt";
File file = new File(fileName);
File dirAsFile = file.getParentFile();
使用此代码,您将使用外部或内部存储路径获取ur文件的路径
答案 1 :(得分:0)
使用它来获取特定文件
File dir = new File (Environment.getExternalStorageDirectory().getAbsolutePath() + "/PersonData");
File file = new File(dir, "Data.pdf");
这里Data.pdf是我的" PersonData"中的文件名。外部存储中的命名文件夹
答案 2 :(得分:0)
我希望这会对你有所帮助:
public static long getExternalStorageAvailableSpace() {
long availableSpace = -1L;
try {
StatFs stat = new StatFs(Environment.getExternalStorageDirectory() .getPath());
stat.restat(Environment.getExternalStorageDirectory().getPath());
availableSpace = (long) stat.getAvailableBlocks() * (long) stat.getBlockSize();
} catch (Exception e) {
e.printStackTrace();
}
return availableSpace;
}
答案 3 :(得分:0)
我还没有 在menifest中添加这两个权限
r JOIN hits as h ON h.id = r.id WHERE (r.date >= now() - INTERVAL 1 DAY) ORDER BY h.hits DESC LIMIT 0,8