关于Environment 的用法(一)

        HttpUtils httpUtils = new HttpUtils();
        //获取sdcard 的根目录
        String sdcard_root = Environment.getExternalStorageDirectory()
                .getAbsolutePath();
        // http://172.55.55.555:8080/allServer/All1601.apk
        //截取文件名
        String fileName = apkUrl.substring(apkUrl.lastIndexOf("/") + 1);
        final String path = sdcard_root + "/all/apk";
        File directory = new File(path);
        if (!directory.exists()) {
            directory.mkdirs();
        }
        // 完整的文件路径
        final String target = path + "/" + fileName;
        // 文件存在,download可能会出错
        File oldFile = new File(target);
        if (oldFile.exists()) {
            oldFile.delete();
        }

你可能感兴趣的:(sdcard)