如何使Android文件的代码在SD卡中移动?

如何使Android文件的代码在SD卡中移动?,android,Android,我将制作生根工具。但是我需要文件移动源代码,请告诉我关于它的代码?。。。 对不起,请回答我 **`" How to make the Code for Android File Moving in the SDcard "`** 要将文件从一个位置移动到另一个位置,可以使用以下方法: private void moveFile(String inputPath, String outputPath) { System.out.println(inputPath); Syste

我将制作生根工具。但是我需要文件移动源代码,请告诉我关于它的代码?。。。 对不起,请回答我

**`" How to make the Code for Android File Moving in the SDcard "`**

要将文件从一个位置移动到另一个位置,可以使用以下方法:

private void moveFile(String inputPath, String outputPath) {

    System.out.println(inputPath);
    System.out.println(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);
        out = new FileOutputStream(outputPath);

        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).delete();

    }catch (FileNotFoundException fnfe1) {
        Log.e("File not found exception", fnfe1.getMessage());
    } catch (Exception e) {
        Log.e("Other Exception", e.getMessage());
    }

}
要调用此方法,可以执行以下操作:

moveFile(Environment.getExternalStorageDirectory() + "/download/abc.txt", Environment.getExternalStorageDirectory() + "/abc.txt");
您还需要在AndroidManifest.xml中授予写入权限


是否要在sdcard中编写创建文件的代码?@HimanshuAgarwal否如果文件在/sdcard/download/abc.txt中,请按按钮将此文件移动到/sdcard/abc.txt检查此答案的实际代码在哪里?是否可能重复忘记添加写入权限?
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>