File.mkdir()和mkdirs()创建文件,而不是目录 [英] File.mkdir() and mkdirs() are creating file instead of directory

查看:1072
本文介绍了File.mkdir()和mkdirs()创建文件,而不是目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用下面的code:

final File newFile = new File("/mnt/sdcard/test/");
newFile.mkdir(); // if I use mkdirs() result is the same

和它创建一个空文件!为什么呢?

And it creates an empty file! Why?

推荐答案

您不会用mkdirs(),除非你想在每一个结构这些文件夹的创建。尝试在你的字符串的结尾不添加多余的斜杠,看看是否能工作。

You wouldn't use mkdirs() unless you wanted each of those folders in the structure to be created. Try not adding the extra slash on the end of your string and see if that works.

例如

final File newFile = new File("/mnt/sdcard/test");
newFile.mkdir();

这篇关于File.mkdir()和mkdirs()创建文件,而不是目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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