Skip to content

Instantly share code, notes, and snippets.

@AswinpAshok
Created November 13, 2019 10:59
Show Gist options
  • Save AswinpAshok/7f52d9293fa2825a3e1b1fd8ff8d106e to your computer and use it in GitHub Desktop.
Save AswinpAshok/7f52d9293fa2825a3e1b1fd8ff8d106e 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