• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

File query

 
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ranchers,
In a jqplus explan, it was written,
"
A file object is only an abstract representation of file and directory pathnames.
If the file doesn't exist nothing is created. But if you try to open a FileInput or FileOutputString using this File object, it will throw a FileNotFoundException. "
Is this statement right.
I think " But if you try to open a FileInput or FileOutputString using this File object, it will throw a FileNotFoundException. "
Here, the file will be created if it does not exist or else a file if exists will be replaced.
Any comments???
Pl help
padmini
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi,

A File object is an abstract representation of file or directory pathnames. If the file/directory doesn't exist il will not be created when you create the File object.
If you try to create a FileInputStream using a File object which represents an inexistent file you will get and FileNotFoundException - because you try to open an inexistent file.
If you try to create a FileOutputStream using the same File object, the file will be created !!
I think it is quite intuitive:
- when you try to read from a file, the file must exist.
- when you want to write something to a file you have to create the file.
Hope it helps...
 
Don't mess with me you fool! I'm cooking with gas! Here, read this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic