• Post Reply Bookmark Topic Watch Topic
  • New Topic

Not able to create Directory with the below code  RSS feed

 
suraj malla
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not able to create Directory with the below code..can any one help me with this.

 
Paul Clapham
Sheriff
Posts: 22835
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, the mkdir() method and the createNewFile() method both return booleans which tell you whether the requested action was successful. But you are ignoring that information. Likewise most of the methods in the PrintWriter class ignore exceptions; there's a checkError() method which you could call to find out if there were any exceptions. But you aren't doing that either.

However the PrintWriter constructor which you used will throw an exception if there's a problem with finding or creating the file you asked it to use. Do you have code elsewhere which handles that exception? Or is there a stack trace which you are ignoring?
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
suraj malla wrote:Not able to create Directory with the below code..can any one help me with this.


I don't see how that could even compile, seeing as the class is named File and it doesn't have constructors that take the parameters supplied, nor the methods invoked.

It's usually bad practice to name your own classes the same as a JDK class.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
suraj malla wrote:Not able to create Directory with the below code..can any one help me with this.

What DOES it do? Does it compile? Does it throw an exception? Does it create a directory with a different name?

We can't really help you unless you TellTheDetails. After all, ItDoesntWorkIsUseless.
 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Works for me using eclipse juno and jdk1.7.0_25. What exception/problem are you seeing?
 
nipun yv
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you should try this:


Since your named your class as file which is same as class File provided by java located in package "java.io". You can specify fully qualified name " java.io.File" otherwise compiler will think that you are trying to use your own File class.
I hope this helps.

Test code:
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
James Boswell wrote:Works for me using eclipse juno and jdk1.7.0_25. What exception/problem are you seeing?

James, you didn't have that code in a class named File, did you?
 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darryl, no, I didn't.

I was under the impression that the OP was able to run this code but was not able to create the intended directory and file. I was able to achieve this.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!