Im new to java. I just learned how to create a file, the type u can store data in( File data = new File). I have a question how can i go about about creating a file and have it install or appear certain directories, like on my desktop?
I tried using mkdir, but im not really sure how to write the code. I looked up several sites that show how to use mdkir, but they didn't seem to help me
Hope someone can help.
creating a file
Page 1 of 111 Replies - 402 Views - Last Post: 21 June 2009 - 07:12 PM
Replies To: creating a file
#2
Re: creating a file
Posted 21 June 2009 - 04:39 PM
So you just want to make a directory? Just create a file of the directory and call the mkdir method on it
File f = new File("C:/Users/Nick/Desktop");
boolean b = f.mkdir();
#3
Re: creating a file
Posted 21 June 2009 - 05:47 PM
Hey nick, thanks for replying to my problem.
From the example you showed me, i created this small code, to get a better grasp and understanding how mkdir works. But i ran into a small promblem, the code executes without any errors, but the file never apperar on my desktop, do uou know why?
Here the code
From the example you showed me, i created this small code, to get a better grasp and understanding how mkdir works. But i ran into a small promblem, the code executes without any errors, but the file never apperar on my desktop, do uou know why?
Here the code
import java.io.*;
public class CreateFile1{
public static void main(String[] args) throws IOException{
File f = new File("C:/Users/Solris/Desktop");
boolean b = f.mkdir();
BufferedWriter output = new BufferedWriter(new FileWriter(f));
output.write("Testing");
output.close();
}
}
#4
Re: creating a file
Posted 21 June 2009 - 05:59 PM
Make sure you do your c: location correctly. You didnt just replace your name with mine did you? Also, I dont know what your root is set to so the location might look a bir different to that,
#5
Re: creating a file
Posted 21 June 2009 - 06:12 PM
I checked the directory again, it seems to be right. Just to make sure the directory is correct, i created a new folder on my desktop and used that directoy.
Please bare with me, like i said im new to java, but Im a little confused when you talked about root of my location?
Please bare with me, like i said im new to java, but Im a little confused when you talked about root of my location?
#6
Re: creating a file
Posted 21 June 2009 - 06:16 PM
the mkdir method creates the directory for you. You shouldnt be making it yourself. What ide are you using? netbeans?
#7
Re: creating a file
Posted 21 June 2009 - 06:20 PM
At the moment im using netbeans IDE 6.5.1
#8
Re: creating a file
Posted 21 June 2009 - 06:37 PM
ok. For the time being then, change this line to
And see if it makes a directory in your netbeans project folder. I made a mistake in my original post anyway, didnt specify a name for the directory.
File f = new File("test");
And see if it makes a directory in your netbeans project folder. I made a mistake in my original post anyway, didnt specify a name for the directory.
#9
Re: creating a file
Posted 21 June 2009 - 06:39 PM
#10
Re: creating a file
Posted 21 June 2009 - 06:45 PM
Sorry, my fault, I asked what ide he was using so i could instruct him to create it straight into the root directory rather than mess about with adding all the c: etc. I am hoping anyways, that just giving it a name like he is going to do, it will place the new directory straight into his project folder.
#11
Re: creating a file
Posted 21 June 2009 - 07:06 PM
Hey nick, thx for all your help, but i made the changes as you directed, as you can see. But the file never appears on my desktop or in the project directory.
import java.io.*;
public class CreateFile1{
public static void main(String[] args) throws IOException{
File f = new File("test");
boolean b = f.mkdir();
BufferedWriter output = new BufferedWriter(new FileWriter(f));
output.write("Testing");
output.close();
}
}
#12
Re: creating a file
Posted 21 June 2009 - 07:12 PM
nick2price, on 21 Jun, 2009 - 05:45 PM, said:
Sorry, my fault, I asked what ide he was using so i could instruct him to create it straight into the root directory rather than mess about with adding all the c: etc. I am hoping anyways, that just giving it a name like he is going to do, it will place the new directory straight into his project folder.
No offense Nick
just want to make sure we are not confusing IDE and Java problems
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote




|