Win a copy of Murach's MySQL this week in the JDBC and Relational Databases 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

createNewFile( )

Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone,
This is the code as below:
f.createFile( )
the complier show that that is a bug

import*;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?
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic