如何用java创建目录和子目录结构? [英] How to create a directory and sub directory structure with java?

查看:97
本文介绍了如何用java创建目录和子目录结构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我想用java创建目录和子目录。
我的目录结构是从当前应用程序目录开始,当前项目目录中的表示如下所示...

Hello there I want to create the directories and sub directories with the java. My directory structure is starts from the current application directory, Means in current projects directory which looks like following...

Images
   |
   |+ Background
   |
   |+ Foreground
          |
          |+Necklace
          |+Earrings
          |+Etc...

我知道如何创建目录,但我需要创建子目录,我尝试使用以下代码后续步骤应该是什么?

I know how to create directory but I need to create sub directory I tried with following code what should be next steps ?

File file = new File("Images");
file.mkdir();


推荐答案

你可以使用 File.mkdir() File.mkdirs()创建目录。在这两者之间,后一种方法更宽容,并将根据需要创建所有中间目录。此外,由于我发现您在问题中使用\\,我建议使用 File.separator ,用于可移植路径分隔符字符串。

You can use File.mkdir() or File.mkdirs() to create a directory. Between the two, the latter method is more tolerant and will create all intermediate directories as needed. Also, since I see that you use "\\" in your question, I would suggest using File.separator for a portable path separator string.

这篇关于如何用java创建目录和子目录结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆