首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

稽查盘volumn是否可以写入

2012-09-21 
检查盘volumn是否可以写入通过创建一个临时文件来确定是否盘可写。注意不要把文件放在根目录,因为根目录会

检查盘volumn是否可以写入
通过创建一个临时文件来确定是否盘可写。注意不要把文件放在根目录,因为根目录会现在文件的数目

private static boolean checkFsWritable() {        // Create a temporary file to see whether a volume is really writeable.        // It's important not to put it in the root directory which may have a        // limit on the number of files.        String directoryName =                Environment.getExternalStorageDirectory().toString() + "/DCIM";        File directory = new File(directoryName);        if (!directory.isDirectory()) {            if (!directory.mkdirs()) {                return false;            }        }        File f = new File(directoryName, ".probe");        try {            // Remove stale file if any            if (f.exists()) {                f.delete();            }            if (!f.createNewFile()) {                return false;            }            f.delete();            return true;        } catch (IOException ex) {            return false;        }    }

热点排行