Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static void copy(InputStream source, File dest) {
- try {
- OutputStream out = new FileOutputStream(dest);
- byte[] b = new byte[1024];
- int len;
- while((len = source.read(b)) > 0) out.write(b, 0, len);
- out.close();
- source.close();
- }
- catch (IOException e) {
- e.printStackTrace();
- }
- }
- /**
- *
- * @param source file to copy from
- * @param dest file to override
- */
- public static void copy(File source, File dest) {
- try
- {
- InputStream in = new FileInputStream(source);
- copy(in, dest);
- }
- catch (IOException e) {
- e.printStackTrace();
- }
- }
- /**
- *
- * @param source folder to copy from
- * @param dest folder to override
- */
- public static void copyFolder(File source, File dest) {
- if (!source.isDirectory()) return;
- dest.mkdirs();
- File[] files = source.listFiles();
- if (files == null || files.length == 0) return;
- for (File file : files)
- {
- if (file.isDirectory()) {
- copyFolder(file, new File(dest + File.separator + file.getName()));
- }
- else {
- copy(file, new File(dest, file.getName()));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement