• Post Reply Bookmark Topic Watch Topic
  • New Topic

createNewFile( )

 
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

code:
--------------------------------------------------------------------------------
import java.io.*;public class FileInfo{public static void main(String args[]){// open (or create) fileFile f= new File ("readme.txt");if( !f.exists())f.createNewFile();// display file informationSystem.out.println("File Information");System.out.println("Name:" + f.getName());System.out.println("Path:"+ f.getAbsolutePath());System.out.println("Size:" + f.length()+ "bytes");if(f.canRead())System.out.println("File can read");if(f.canWrite())System.out.println("File can be written to");f.delete();}}
--------------------------------------------------------------------------------

Do you know what wrong it is?
thanks
Larry
 
Tanel Alumae
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to mention that your post is quite messy. First, if you post any code, put it between the CODE tags using the button below the text box where you enter the text. Next, you say that the compiler says that the expression f.createFile() has problems, but your code doesn't even seem to have that line, so I assume that you mean the expression f.createNewFile(). Third, you don't mention what does the compiler say about that line. Probably you are just not catching the IOException that the method can throw. Alternatively you can declare the main method to throw that exception.
[ September 11, 2002: Message edited by: Tanel Alumae ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!