Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


FileWriter Wont Write To Directory

FileWriter Wont Write To Directory

FileWriter Wont Write To Directory

I wish to save a file if i put c:\\file.txt, the file is saved in the c: drive, however if i put c:\\dir\\file.txt it doesnt work. What am I doing wrong? (I am working on Windows 2000)

        try {
            out = new BufferedWriter(new FileWriter("c:\\file.txt, true));
            out.write(new Date() + " : " + lm + '\n');
        } catch (Exception e) {
            if (out != null) {
                try {
                } catch (Exception er) {

RE: FileWriter Wont Write To Directory

...and the C:\dir directory definitely exists?


RE: FileWriter Wont Write To Directory

Ahh, no it doesnt and works a treat when it is there. My low point of today!!!

Is there a way of creating the directory if it does not exist?

Thanks :)

RE: FileWriter Wont Write To Directory

Have a read of the File javadoc ...


File dir = new File("C:/dir");
if (!dir.exists()) {

dir = new File("C:/dir");
if (!dir.exists()) {
   throw new IOException("Could not make dir : " +dir);

Free Java/J2EE Database Connection Pooling Software

RE: FileWriter Wont Write To Directory

Look at the mkdir method of the File class.

Bob Rashkin

RE: FileWriter Wont Write To Directory

Thank you very much that is a great help :)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close