Skip to content

Instantly share code, notes, and snippets.

@AswinpAshok
Created November 13, 2019 10:59
Show Gist options
  • Save AswinpAshok/bf39e88b9e7346b92d20c05e62fe8ca0 to your computer and use it in GitHub Desktop.
Save AswinpAshok/bf39e88b9e7346b92d20c05e62fe8ca0 to your computer and use it in GitHub Desktop.
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);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment