Win a copy of TensorFlow 2.0 in Action 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

createNewFile( )

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