• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to create a file in specified directory  RSS feed

 
Kiran Baratam
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I am trying to create a file in a directory in append mode.Its not getting creayed.here is the code.Can you please help me.
FileWriter fNew = new FileWriter("C:/xml/newXML.xml,true);
i am able to create a file directly under c:/ like
FileWriter fNew = new FileWriter("C:/newXML.xml,true);
when i try to create in xml directory which is already exists under c its giving an exception.

Regards
Kiran
[ December 01, 2003: Message edited by: Kiran Baratam ]
 
Joe Ess
Bartender
Posts: 9426
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the exception and contents of the stack trace?
 
Ashish Gupta
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kiran,
When creating a file you will have to make sure that the directory under which the file has to be created exsist. In your particular case you can use following code

Also, don't forget to 'escape' the forward/backward slash.
HTH
Ashish
 
Joe Ess
Bartender
Posts: 9426
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ashish Gupta:
Kiran,
When creating a file you will have to make sure that the directory under which the file has to be created exsist.

She states that the directory does exist.

Also, don't forget to 'escape' the forward/backward slash.

Forward-leaning slashes, like those used in Unux paths, do not need to be escaped and also work fine in Windows.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!