Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Files

 
Balaji Bang
Ranch Hand
Posts: 182
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

in K&B it is given :

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

But the following is giving FileNOtFoundException


This is working fine when I used PrintWriter and FileWriter . Not working only for FileReader . Why please explain...........
 
Stephen Davies
Ranch Hand
Posts: 352
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
File is not a file on your system. new File("MyFile.txt") is creating a new File Object from where you can call various Methods, to create a file on the system, such as .createNewFile(). If your using Sierra & Bates JAVA 5 see page 431, for more details. The example given there is:



Its a simple method for giving feedback on the existence of files, so;



 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic