Android以编程方式将文件夹移动到另一个文件夹

时间:2015-04-03 22:06:17

标签: android directory

我想在Android中知道如何将目录(文件夹)而不是文件从目录移动到另一个目录。我该怎么办,我使用了这个功能:

private void moveFile(String inputPath, String inputFile, String outputPath) {

    InputStream in = null;
    OutputStream out = null;
    try {
        //create output directory if it doesn't exist
        File dir = new File (outputPath); 
        if (!dir.exists())
        {
            dir.mkdirs();
        }

        in = new FileInputStream(inputPath + inputFile);        
        out = new FileOutputStream(outputPath + inputFile);

        byte[] buffer = new byte[1024];
        int read;
        while ((read = in.read(buffer)) != -1) {
            out.write(buffer, 0, read);
        }
        in.close();
        in = null;

        // write the output file
        out.flush();
        out.close();
        out = null;

        // delete the original file
        new File(inputPath + inputFile).delete();
    } 

    catch (FileNotFoundException fnfe1) {
        Log.e("tag", fnfe1.getMessage());
    }
    catch (Exception e) {
        Log.e("tag", e.getMessage());
    }
}

我放了读写权限,但它只移动文件而不移动文件夹。

0 个答案:

没有答案
相关问题