Win a copy of Zero to AI - A non-technical, hype-free guide to prospering in the AI era this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

createWrite( )

 
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
 
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 ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic