Create a directory if it does not exist and then create the files in that directory as well

前端 未结 7 1240
礼貌的吻别
礼貌的吻别 2020-12-12 14:36

Condition is if directory exists it has to create files in that specific directory with out creating a new directory.

The below code only creating a file with new di

7条回答
  •  一向
    一向 (楼主)
    2020-12-12 15:08

    code:

    // Create Directory if not exist then Copy a file.
    
    
    public static void copyFile_Directory(String origin, String destDir, String destination) throws IOException {
    
        Path FROM = Paths.get(origin);
        Path TO = Paths.get(destination);
        File directory = new File(String.valueOf(destDir));
    
        if (!directory.exists()) {
            directory.mkdir();
        }
            //overwrite the destination file if it exists, and copy
            // the file attributes, including the rwx permissions
         CopyOption[] options = new CopyOption[]{
                    StandardCopyOption.REPLACE_EXISTING,
                    StandardCopyOption.COPY_ATTRIBUTES
    
            };
            Files.copy(FROM, TO, options);
    
    
    }
    

提交回复
热议问题