• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

File IO

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is from pg 439 of K&B book

it mentions that there are 2 ways to create a file
1. Invoke the createNewFile() method on a File ojbect.

2. Create a Reader or a Writer or a Stream. Specifically, create a FileReader, a FileWriter, a PritWriter, a FileInputStream, or a FileOutputStream. Whenever you create an instance of one of those classes, you automatically create a file, unless one already exists.

I tried the following set of codes one by one











the first 3 created a new file as described in the book.
but for the last 2(FileReader and FileInputStream), FileNotFoundException.

can someone explain me what's wrong with my code???

or is it the typo error of the book?

regards
Terence
 
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Terence,
No Reader or InputStream will create a file ,if the file not exists.It will throw an FileNotFoundException if there is a directory exits name being the same as the file or does not finds the file specified.
I think this is a errata in K&B book.
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Regarding K & B, when in doubt, check this out.
 
Terence Thant Zin Oo
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks Barry for your link

yeah. this is listed as errata in that thread

regards
terence
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic