Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • 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!

Join Tek-Tips
*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.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

FileWriter Wont Write To Directory

bobrivers2003 (TechnicalUser) (OP)
16 May 06 9:37
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');
            out.close();
                
        } catch (Exception e) {
    
            if (out != null) {
    
                try {
                    out.close();
                        
                } catch (Exception er) {
                
                }
    
            }
        }

timw (Programmer)
16 May 06 9:55
...and the C:\dir directory definitely exists?

Tim

bobrivers2003 (TechnicalUser) (OP)
16 May 06 9:59
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 :)
sedj (Programmer)
16 May 06 10:15
Have a read of the File javadoc ...

CODE


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

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

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
http://www.primrose.org.uk

Bong (Programmer)
16 May 06 10:17
Look at the mkdir method of the File class.

_________________
Bob Rashkin

bobrivers2003 (TechnicalUser) (OP)
16 May 06 10:35
Thank you very much that is a great help :)

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!

Back To Forum

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