Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Java Javatutorial Create File in Java

Related Tutorials


 
 

Share on Google+Share on Google+

Create File in Java

Advertisement
File is nothing but a simple storage of data in Java language. We call one object that belongs to java.io package and we use it to store name of the file or directory and also use the pathname. File is collection of stored information that are arranged in String, column and row line. This example stores file name and text data to the file. The File.createNewFile() method is used to create a file in java.

File is nothing but a simple storage of data in Java language. We call one object that belongs to java.io package and we use it to store name of the file or directory and also use the pathname. File is collection of stored information that are arranged in String, column and row line. This example stores file name and text data to the file.

The File.createNewFile() method is used to create a file in java. This method returns a Boolean value "true" if the file is created successfully, "false" if the File is not created.

NewFile() method returns "false" if the file is already created or the operation has failed.

Example of how to create a file in java:

package FileHandling;

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

public class FileCreate {
	public static void main(String[] args) throws IOException {
		File file = new File("c:/Test.txt");
		if(file.createNewFile()){
			System.out.println("File is created");
		}else
		System.out.println("File is already created");
	}

}

Output:

File is created

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: May 6, 2013

Related Tutorials

Discuss: Create File in Java  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com