Files.list为android数据/数据设备返回null为root

时间:2014-05-20 12:39:57

标签: android root android-file

我试图在/data/data/中生成特定目录中所有文件的列表,例如/data/data/com.package.ect以便我可以拉链。我的设备已植根,我已将超级用户授予我的应用。将路径传递给目录时,它会通过if语句,因此它会识别出我尝试访问的是一个目录,但File.list()返回null。我假设我仍然缺乏某种许可。

/**
     * Traverse a directory and get all files,
     * and add the file into fileList
     * @param node file or directory
     */
    public void generateFileList(File node) {

        //add file only
        if (node.isFile()) {
            fileList.add(generateZipEntry(node.getAbsoluteFile().toString()));
        }

        if (node.isDirectory()) {
            String[] subNote = node.list();
            for (String filename : subNote) {
                generateFileList(new File(node, filename));
            }
        }
    }

*编辑:根据请求调用generateFileList

public void zipDirectory(String outputPath){

        byte[] buffer = new byte[1024];

        try{
            checkStorageDirExists(SDCARD, STORAGE_LOCATION);
            generateFileList(new File(path));
            FileOutputStream fos = new FileOutputStream(SDCARD + STORAGE_LOCATION + outputPath);
            ZipOutputStream zos = new ZipOutputStream(fos);
            setZipFileName(path);

            Log.i(TAG, "Output to Zip : " + outputPath);

            for(String file : this.fileList){

                System.out.println("File Added : " + file);
                ZipEntry ze= new ZipEntry(file);
                zos.putNextEntry(ze);

                FileInputStream in =
                        new FileInputStream(path + "/" + file);

                int len;
                while ((len = in.read(buffer)) > 0) {
                    zos.write(buffer, 0, len);
                }

                in.close();
            }

            zos.closeEntry();
            zos.close();

            Log.i(TAG, "Zip of " + getZipFileName() +" Completed");
        }catch(IOException ex){
            ex.printStackTrace();
        }

0 个答案:

没有答案