在创建文件时,如果路径中的目录(或文件)不存在,则一并生成,方法如下:

/**
     *@Description 创建文件
     *@Author zrt
     *@Param
     *@Date 2020/7/13 10:03
     */
    public static void createFile(String path){
        File file = new File(path);

        if(!file.getParentFile().exists()){
            try {
                file.getParentFile().mkdirs();
                file.createNewFile();
//                System.out.println("创建成功!");

            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    }

 

相关文章:

  • 2021-06-08
  • 2021-05-06
  • 2021-05-30
  • 2022-03-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-01
猜你喜欢
  • 2021-06-15
  • 2021-10-28
  • 2022-12-23
  • 2022-12-23
  • 2021-06-05
  • 2021-09-18
  • 2021-06-26
相关资源
相似解决方案