• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Creating a PrintWriter object in Windows.

 
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm creating a PrintWriter object.
The first approach below is okay but not the second one.
Could someone please tell me what I'm doing wrong?

First approach:


Second approach:
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does the file "C:\myprojects\12345.xml" exist?
What is printed when you print new File("12345.xml").getAbsolutePath()?
 
Susan Smith
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> Does the file "C:\myprojects\12345.xml" exist?
No, but that's what I'm actually wondering. If I don "12345.xml" it will create the file if it doesn't exist. Why not in this case?

> What is printed when you print new File("12345.xml").getAbsolutePath()?
C:\myprojects\
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[Susan]: The first approach below is okay but not the second one.

What exactly is wrong with the second? Does it throw an exception? If so, what's the error message? Or does somethign else go wrong?

[Susan]: No, but that's what I'm actually wondering. If I don "12345.xml" it will create the file if it doesn't exist. Why not in this case?

Well, maybe the directory doesn't exist. Or maybe the directory exists but you don't have write access. If the file already exists, then it coudl be that you don't have access to overwrite it. Or maybe there's a stream open somewhere writing to the file or reading from it.

[Susan]: > What is printed when you print new File("12345.xml").getAbsolutePath()?
C:\myprojects\


Um, really? With no 12345.xml at the end? That's extremely weird. You sure about that?
[ December 04, 2007: Message edited by: Jim Yingst ]
 
Susan Smith
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
>> What's wrong with the second one?
File Not Found Exception

>> Um, really? With no 12345.xml at the end? That's extremely weird.
>> You sure about that?
Ops, you're right.
 
Rob Spoor
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From the API, about when FileNotFoundException is thrown:

if the file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason.


The first case does not seem to be the problem, but have you tested the second one? Can you write other files to that directory?

And can you show us the stack trace?
reply
    Bookmark Topic Watch Topic
  • New Topic