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?
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.
luck, db
There are no new questions, but there may be new answers.
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.
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.
So I left, I came home, and I ate some pie. And then I read this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss