File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes I/O and Streams and the fly likes createWrite( ) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "createWrite( )" Watch "createWrite( )" New topic
Author

createWrite( )

Larry Lai
Ranch Hand

Joined: May 13, 2002
Posts: 44
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

Joined: Jun 06, 2002
Posts: 1056
What specific problem are you having?


Ron Newman - SCJP 1.2 (100%, 7 August 2002)
Larry Lai
Ranch Hand

Joined: May 13, 2002
Posts: 44
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

Joined: Jun 06, 2002
Posts: 1056
I still don't understand. What is the compiler saying? Show us the entire error message.
Larry Lai
Ranch Hand

Joined: May 13, 2002
Posts: 44
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

Joined: Jun 06, 2002
Posts: 1056
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: createWrite( )