Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void copyFiles(String copyLoc, File files) throws FileNotFoundException {
- File copyFile = new File(copyLoc);
- // Create the directory for the new copy location
- if (copyFile.mkdir()) {
- try {
- int transferBytes;
- FileOutputStream outputStream = new FileOutputStream(copyFile);
- for (File f : files.listFiles()) {
- // list all files and if there is a directory in the first place open it with recursion
- System.out.println("listing files:" + Arrays.toString(files.listFiles()));
- if (f.isDirectory()) {
- System.out.println("directory recursion open: " + f.getAbsolutePath());
- copyFiles(f.getAbsolutePath(), f);
- }else if (f.isFile()) {
- FileInputStream inputStream = new FileInputStream(f);
- while ((transferBytes = inputStream.read()) != -1) {
- System.out.println(transferBytes);
- outputStream.write(transferBytes);
- }
- }
- }
- } catch (IOException ex) {
- ex.getLocalizedMessage();
- }
- }
- }
- //--------------------------------------------------------------------------
- /*
- //This is an old recursive directory method that printed the folder it was opening and the size
- if (file.isDirectory()) {
- for (File f : file.listFiles()) {
- long size = (f.length()/1000000);
- if (f.isDirectory()) {
- if(size >= 1) {
- System.out.println("Folder: " + f.getAbsolutePath() + "\nSize: " + size + " mb");
- }else{
- System.out.println("Folder: " + f.getAbsolutePath() + "\nSize: " + f.length() + " bytes");
- }
- printDir(f.getAbsoluteFile());
- }else if(f.isFile()) {
- if(size >= 1) {
- System.out.println("File: " + f.getName() + "\nSize: " + size + " mb");
- }else{
- System.out.println("File: " + f.getName() + "\nSize: " + f.length() + " bytes");
- }
- }else if(f.isHidden()) {
- if(size >= 1) {
- System.out.println("Hidden: " + f.getName() + "\nSize: " + size + " mb");
- }else{
- System.out.println("Hidden: " + f.getName() + "\nSize: " + f.length() + " bytes");
- }
- }else {
- System.out.println("Something is here but we cannot see it.");
- }
- }
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement