-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileUtil.java
63 lines (51 loc) · 1.35 KB
/
FileUtil.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package com.movisens.xs.android.core.utils;
import java.io.IOException;
import java.io.OutputStream;
import java.io.InputStream;
import org.odk.collect.android.utilities.FileUtils;
public class FileUtil {
public static int s = 4000;
public static byte[] Puffer = new byte[s];
public static void deleteRecursive(File FILEOrDirectory) {
if (FILEOrDirectory.isDirectory())
for (File child : FILEOrDirectory.listFiles())
deleteRecursive(child);
FILEOrDirectory.delete();
}
/**
*
*/
public static int copy(InputStream input, OutputStream output) {
int count = 0;
int n = 0;
try {
while (-1 != (n = input.read(Puffer))) {
output.write(Puffer, 0, n);
count += n;
}
} catch (Exception e) {
e.printStackTrace();
}
return count;
}
public static void copyFolder(File src, File dest) {
if (src.isDirectory()) {
// if directory not exists, create it
if (!dest.exists())
dest.mkdir();
// list all the directory contents
String files[] = src.list();
for (String file : files) {
// construct the src and dest file structure
File srcFile = new File(src, file);
File destFile = new File(dest, file);
// recursive copy
copyFolder(srcFile,destFile);
}
} else {
// if file, then copy it
FileUtils.copyFile(src, dest);
System.out.println("File copied from " + src + " to " + dest);
}
}
}