Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

createWrite( )

 
Larry Lai
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,
This is the code as below:
f.createFile( )
the complier show that that is a bug


Do you know what wrong it is?
thanks
Larry
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What specific problem are you having?
 
Larry Lai
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ron,
How're you ?
I mean the complier reply that the f.createFile( )
causes the problem.
I'm not sure what wrong it is...
Larry
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I still don't understand. What is the compiler saying? Show us the entire error message.
 
Larry Lai
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ron,

the compiler replys about as below:


--------------------Configuration: JDK version 1.31 <Default>--------------------
C:\Documents and Settings\labuser\Desktop\FileInfo.java:11: unreported exception java.io.IOException; must be caught or declared to be thrown
if( !f.exists())f.createNewFile();
^
1 error
Process completed.
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's fairly self-explanatory, no? If you call the method f.createNewFile(), you need to do so within a try-block that catches IOException.
I don't know exactly what IO exceptions can arise, but I'd guess one of them will occur if the file name isn't valid, includes directories that don't actually exist, or names a file that can't be created because you don't have the right permissions.
[ September 04, 2002: Message edited by: Ron Newman ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic