• 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

I/O doubt

 
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI ALL....
i am preparing for scjp5 using k&b....
Page 439-chapter 6......he said that the actual file does not created unless you call File.craeteNewFile(), create Reader or Write classes BUT:
when you do that:
try{
File f=new File("myFile.txt");
FileReader fr=new FileReader(f);
}catch(Exception ex1){ex1.printStackTrace();}
Then THERE ARE EXCEPTION : java.io.FileNotFoundException
AND no files created.........
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes it is an error in the book, InputStreams and Readers do not create files, and is noted here in the errata: temporary K&B 5 errata

Kristian
 
Ranch Hand
Posts: 584
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So Kristian do you mean only FileWriter creates a new file if no such file exists ?
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Both FileWriter and PrintWriter exhibit that behaviour. If no file exists then a new file is created.
 
Edisandro Bessa
Ranch Hand
Posts: 584
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Huuumm. Thanks John for your prompt reply. I will not forget it !
 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
more about it
also FileOutputStream and Formatter will creates files if no such file exists.
so for preparing the exam,PrintWriter,FileWriter,FileInputStream,Formatter will creaate files if no such files exists
[ April 16, 2006: Message edited by: Changchun Wang ]
 
Edisandro Bessa
Ranch Hand
Posts: 584
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank U Changchun.
 
Alan Hermin
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey Changchun Wang.....

so for preparing the exam,PrintWriter,FileWriter,FileInputStream,Formatter will creaate files if no such files exists



NO...FileInputStream does not create one if does not exist...
 
reply
    Bookmark Topic Watch Topic
  • New Topic