Silvr Swrd
Silvr Swrd

Reputation: 59

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

Upvotes: 1

Views: 147

Answers (2)

Devilhorn
Devilhorn

Reputation: 102

Don't worry this folder will be created automatically direct from the File(class) code which is the best option:check this out too...

import java.io.*;

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

Upvotes: 1

user3902960
user3902960

Reputation: 11

I will direct you to the 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();
}

Upvotes: 1

Related Questions