Maing a directory using mkdir()
I am trying to make a file and a containing folder inside my programs source.
the code doesnt seem to ever thing the file is created, and the folder/file never show up.
Code Java:
import java.io.File;
import java.io.FilenameFilter;
public class Startup {
Print p = new Print();
File data = new File("data\\data.txt");
ReadingLine rl = new ReadingLine();
String temp="";
@SuppressWarnings("static-access")
public Startup()
{
if(!data.exists())
{
data.mkdir(); //this doesnt make the folder data or file data.txt
p.pl("Hello, I am System, Since this is your first time using me I need to ask you some questions.");
p.pl("What is your name?");
temp = rl.readLine();
User.setName(temp);
}
}
}
Re: Maing a directory using mkdir()
See the API for File, the mkdir() returns a boolean if and only if the directory was created - you can use this to evaluate programatically if the directory was created. Typically, if it returns false something is incorrect with either the Path or permissions. In this case, the path in the 'data' File object seems to be a the path to a file, and I presume the data directory does not exist? You must first create the directory, then create the file - and you do not create a file via the mkdir, this creates directories. To create a file, write to a new file or use the createNewFile method, and its parent directory must exist. In other words, you do not create a folder and directory in one pass (eg the parent folders are not created for you), you must do so independently through different objects.
Edit: Thread moved from the tutorials sections. Please choose the section you post in more carefully in the future.
Re: Maing a directory using mkdir()
Thanks, It works now.
And sorry about posting in the wrong place.