0

I will make rooting-Tool. But I need the File move Source please tell me about it(code)?... I'm so sorry but Answer to me please.

**`" How to make the Code for Android File Moving in the SDcard "`**
Daahrien
  • 10,190
  • 6
  • 39
  • 71
Expolk
  • 23
  • 6

1 Answers1

0

To move your file from one location to another you can use this:

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());
    }

}

To call this method you can do this:

moveFile(Environment.getExternalStorageDirectory() + "/download/abc.txt", Environment.getExternalStorageDirectory() + "/abc.txt");

Also you need to give writing permission in your AndroidManifest.xml

  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Himanshu Agarwal
  • 4,623
  • 5
  • 35
  • 49