Skip to content

Instantly share code, notes, and snippets.

@AswinpAshok
Created November 13, 2019 10:59
Show Gist options
  • Select an option

  • Save AswinpAshok/bf39e88b9e7346b92d20c05e62fe8ca0 to your computer and use it in GitHub Desktop.

Select an option

Save AswinpAshok/bf39e88b9e7346b92d20c05e62fe8ca0 to your computer and use it in GitHub Desktop.

Revisions

  1. AswinpAshok created this gist Nov 13, 2019.
    41 changes: 41 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@

    public void copy(View view) {
    File source = new File("storage/emulated/0/test.apk");
    File dest = new File("storage/emulated/0/test_copy.apk");
    try {
    copyFileUsingStream(source, dest);
    } catch (IOException e) {
    e.printStackTrace();
    }
    }

    private static void copyFileUsingStream(File source, File dest) throws IOException {
    InputStream is = null;
    OutputStream os = null;
    try {
    is = new FileInputStream(source);
    os = new FileOutputStream(dest);
    byte[] buffer = new byte[1024];
    int length;
    while ((length = is.read(buffer)) > 0) {
    os.write(buffer, 0, length);
    }
    } finally {
    is.close();
    os.close();
    }
    }

    public void delete(View view) {
    File dest = new File("storage/emulated/0/test_copy.apk");
    dest.delete();
    }


    public void list(View view) {
    File source = new File("storage/emulated/0/");
    String[] list = source.list();
    for (String s : list) {
    Log.d("ASWIN", "list: "+s);
    }
    }