Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- public class DirMove
- {
- public DirMove()
- {
- }
- public static void copyDir(File quelle, File ziel)
- throws FileNotFoundException, IOException
- {
- File files[] = quelle.listFiles();
- ziel.mkdirs();
- File afile[];
- int j = (afile = files).length;
- for(int i = 0; i < j; i++)
- {
- File file = afile[i];
- if(file.isDirectory())
- copyDir(file, new File((new StringBuilder(String.valueOf(ziel.getAbsolutePath()))).append(File.separator).append(file.getName()).toString()));
- else
- copyFile(file, new File((new StringBuilder(String.valueOf(ziel.getAbsolutePath()))).append(File.separator).append(file.getName()).toString()));
- }
- }
- private static void copyFile(File file, File ziel)
- throws FileNotFoundException, IOException
- {
- in = new BufferedInputStream(new FileInputStream(file));
- out = new BufferedOutputStream(new FileOutputStream(ziel, true));
- for(int bytes = 0; (bytes = in.read()) != -1;)
- out.write(bytes);
- in.close();
- out.close();
- }
- public static boolean delDir(File path)
- {
- File files[] = path.listFiles();
- if(files != null)
- {
- File afile[];
- int j = (afile = files).length;
- for(int i = 0; i < j; i++)
- {
- File file = afile[i];
- if(file.isDirectory())
- delDir(file);
- else
- if(!file.delete())
- return false;
- }
- }
- path.delete();
- return true;
- }
- private static BufferedInputStream in = null;
- private static BufferedOutputStream out = null;
- }
Add Comment
Please, Sign In to add comment