• Post Reply Bookmark Topic Watch Topic
  • New Topic

FileOutputStream

 
Jeff Gaer
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Studing for the SCJP I was supprised to learn that the following code will actually create the file if it doesn't already exist. Whey then does the constructor FileoutputStream(File file) declare that it throws a FileNotFoundException.
public class FileTest {
public static void main(String [] args) throws IOException{
File f= new File(args[0]);
FileOutputStream f1=new FileOutputStream(f);
System.out.println("done");
}
}
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the API:

Throws:
FileNotFoundException - 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

Dave
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!