1
A
回答
4
您可以拨打File#exists()
来确定它是否存在,但如果不存在,也可以拨打File#mkdirs()
自动创建整个路径。
1
我通常使用这种技术:
File folderLocation = new File("/blah/blah/mysystem/myfolder");
if (folderLocation.exists()) {
if (!folderLocation .isDirectory()) {
throw new IOException("File-system item with path [" + folderLocation.getAbsolutePath() + "] exists but is not a folder.");
}
} else {
if (!folderLocation.mkdirs()) {
throw new IOException("Could not create folder with path : " + folderLocation.getAbsolutePath());
}
}
// we are guaranteed that the folder exists here
相关问题
- 1. 如何确定文件夹是否已存在于innosetup
- 2. 确定是否存在XDocument文件
- 3. 确定文件夹是否在文件路径中
- 4. 如何确定指定文件是否放置在指定文件夹内?
- 5. AngularJS - 检查文件夹是否存在
- 6. 检查IMAP是否存在文件夹
- 7. 确定文件夹是否在.NET中共享
- 8. 如何确定文件夹是否嵌套在SharePoint列表中
- 9. 如何确定给定路径是文件还是文件夹?
- 10. 如何确定Outlook文件夹是否公开?
- 11. 快速确定文件夹内容是否已被修改
- 12. 如何检查文件夹中是否已存在文件
- 13. PHP - 检查一个文件夹中是否存在文件
- 14. 如何检测项目文件夹中是否存在文件?
- 15. 检查文件夹中是否存在文件actionScript 3
- 16. Flex 4.5.1检查资产文件夹中是否存在文件
- 17. 检查包/项目中是否存在文件/文件夹
- 18. $ cordovaFile checkFile()查看www文件夹中的文件是否存在?
- 19. PySVN - 确定是否存在存储库
- 20. 确定一个文件列表是否存在于Haskell
- 21. 如何确定文件是否存在于SharePoint SPFolder中
- 22. 通过ftp连接来确定文件是否存在
- 23. 使用Javascript来确定文件是否存在,当地
- 24. 如何确定文件是否存在使用VBA Excel 2007?
- 25. 使用Zend邮件检查邮件文件夹是否存在
- 26. 如何找出文件夹是否存在以及如何创建文件夹?
- 27. 确定文件夹大小
- 28. 代码评论:给出完整的文件路径,确定文件夹是否存在?
- 29. 如何确定“投递文件夹”中的文件是否完全传输
- 30. 确定是否在emberjs存在模板