Pin It

How to create a file in Java ?

Program to demonstrate how to create a file in Java.




Click here to download complete source code 


import java.io.File;
import java.io.IOException;

public class CreateFile {

 public static void main(String[] args) {
  
  File file = new File("test.txt");
  
  try {
  
  if(file.createNewFile()) { 
   System.out.println("File successfully created.");
  } else {
   System.out.println("File already exists.");
  }
  
  } catch(IOException ioe) { 
   System.out.println("IO Exception occured.");
  }

 }

}




Click here to download complete source code 


Please Give Us Your 1 Minute In Sharing This Post!
SOCIALIZE IT →
FOLLOW US →
SHARE IT →
Related Posts Plugin for WordPress, Blogger...

Post your related queries below ...

comments powered by Disqus
Powered by Blogger.
 
© 2012 Learn Java by Examples Template by Hubber Spot