Last active
August 29, 2015 14:07
-
-
Save MikeAfc/28b21e0024c95679ad21 to your computer and use it in GitHub Desktop.
android backup apk file
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
private void testBackupFile() throws IOException { | |
File file = new File("/data/app/fq.router2-2.apk"); | |
if (file.exists()) { | |
Log.d("command", "get file"); | |
File dir = new File("/sdcard/mikeBackUp"); | |
if (!dir.exists()) { | |
dir.mkdirs(); | |
} | |
copyFile(file, new File(dir, "FqRouter.apk")); | |
} else { | |
Log.d("command", "empty file"); | |
} | |
} | |
public void copyFile(File src, File dst) throws IOException { | |
InputStream in = new FileInputStream(src); | |
OutputStream out = new FileOutputStream(dst); | |
// Transfer bytes from in to out | |
byte[] buf = new byte[1024]; | |
int len; | |
while ((len = in.read(buf)) > 0) { | |
out.write(buf, 0, len); | |
} | |
in.close(); | |
out.close(); | |
} | |
public static String readableFileSize(long size) { | |
if(size <= 0) return "0"; | |
final String[] units = new String[] { "B", "KB", "MB", "GB", "TB" }; | |
int digitGroups = (int) (Math.log10(size)/Math.log10(1024)); | |
return new DecimalFormat("#,##0.#").format(size/Math.pow(1024, digitGroups)) + " " + units[digitGroups]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment