mkdir()没有创建新目录 [英] mkdir() is not creating the new directory

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

问题描述

我正在使用Eclipse和jdk1.7。我正在使用文件处理制作基本程序,其中将在目录中创建输出目录。但是当我运行程序时,输出显示为false并且未创建目录。我认为输出是错误的,因为存在具有相同名称的目录,但这不是原因。所以我需要帮助。这是我的代码:

I am using Eclipse and jdk1.7. I am making a basic program using file handling, in which an output directory inside the directory is to be made. But when I run the program, the output is showing false and the directory is not made. I thought that the output was false because of the presence of a directory with the same name, but this is not the reason. So I need help. Here is my code:

import java.io.File;

public class P {
    public static void main(String[] args) {
        File f1 = new File ("abc");
        File f2 = new File (f1,"abc");
        System.out.println(f2.mkdir());
    }
}

其输出为false,但尚未创建任何目录。
如何解决此问题?这不仅仅是在这个程序中 - 我调用方法的每个程序 mkdir()都有同样的问题。

Its output is false and yet no directory has been created. How can I resolve this problem? This is not only in this program - each and every program in which I am calling the method mkdir() is having the same problem.

推荐答案

你必须使用 mkdirs()如果要创建多个目录,请使用s。可能还值得检查一下 canWrite()到某个地方的权限。这两个都在File类

You have to use mkdirs() with an s if you want to create multiple directories. It is probably also worth checking that you canWrite() to the location as some places are permissioned. Both of these are on the File class

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

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