简体   繁体   English

如何在Java中创建文件夹

[英]How to create a folder in java

So, I want to create a file in a folder on the desktop. 因此,我想在桌面上的文件夹中创建一个文件。 But I don't want everyone who downloads the game to have to create that folder. 但是我不希望每个下载游戏的人都必须创建该文件夹。 Is there a way to do this? 有没有办法做到这一点? The did for the folder is: 该文件夹的名称为:

/users/USER/desktop/MyFolder

I will direct you to the File Javadoc. 我将指导您使用File Javadoc。 It contains a few methods for creating new directories and files. 它包含一些用于创建新目录和文件的方法。

Example: 例:

File file = new File("/users/USER/desktop/MyFolder");

if(!file.exists())
{
    file.makeDirs();
}

Don't worry this folder will be created automatically direct from the File(class) code which is the best option:check this out too... 不用担心这个文件夹会直接从File(class)代码自动创建,这是最好的选择:也请检查一下...

import java.io.*;

File myFile=new File("/users/USER/desktop/MyFolder","something..");/*for instance "something.txt"**/ 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM