Using Java nio to create a subdirectory and file

后端 未结 3 1628
死守一世寂寞
死守一世寂寞 2020-12-30 22:53

I\'m creating a simple program that will try to read in \"conf/conf.xml\" from disk, but if this file or dir doesn\'t exist will instead create them.

I can do this u

3条回答
  •  孤城傲影
    2020-12-30 23:07

    You can create directory and file in one code line:

    Files.createFile(Files.createDirectories(confDir).resolve(confFile.getFileName()))

    Files.createDirectories(confDir) will not throw an exception if the folder already exists and returns Path in any case.

提交回复
热议问题