Manager - Copy Directory

public static class copydir {

public static void copydirectory(String src, String dest) {
java.io.File srcFolder = new java.io.File(src);
java.io.File destFolder = new java.io.File(dest);
if(!srcFolder.exists()) {
System.out.println("Directory does not exist.");
//just exit
System.exit(0);
} else {
try{
copyDirectory(srcFolder,destFolder);
} catch(java.io.IOException e) {
e.printStackTrace();
//error, just exit
System.exit(0);
}
}
System.out.println("Done");
}
public static void copyDirectory(java.io.File src , java.io.File target) throws java.io.IOException {
if (src.isDirectory()) {
if (!target.exists()) {
target.mkdir();
}
String[] children = src.list();
for (int i=0; i<children.length; i++) {
copyDirectory(new java.io.File(src, children[i]),new java.io.File(target, children[i]));
}
} else {
java.io.InputStream in = new java.io.FileInputStream(src);
java.io.OutputStream out = new java.io.FileOutputStream(target);
// Copy the bits from instream to outstream
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
}
}
}

Komentar

Cara pembuatan Apps paling Populer

Create Stopwatch App in Android using Sketchware

TextInputLayout in Sketchware

How to find and​ highlight a word in a text field in Sketchware?

A Flash Light App in Sketchware

How to enable download in webview in Sketchware apps?

Intent - Open File By Type

Code for implementing Notifications in Sketchware

How to share an image from Drawable folder?

ActionBar back button

Animation Transtition Animation