Created
November 13, 2019 10:59
-
-
Save AswinpAshok/7f52d9293fa2825a3e1b1fd8ff8d106e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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