Home Tutorial Java Core Files Java file object

 
 

Share on Google+Share on Google+
Java file object
Posted on: June 5, 2006 at 12:00 AM
Advertisement
This section demonstrates you the concept of File object.

Java file object

This section demonstrates you the concept of File object.

Java.io.* package has provide a number of useful  tools which has made the programming much easier. Here we will discus the operations performed by File object.

Using the File object, you can perform several operations. It parses the file to be used for reading or writing purposes. There are various built in functions which shows their utility by just calling them through the object, like creating a file, deleting a file, getting last modification date, renaming a file, getting file name, getting file path, creating a temporary file, creating a directory etc. We have mentioned few of them in the given example.

Here is the code:

import java.io.*;

class FileObject {
	public static void main(String[] args) throws Exception {
		File f = new File("c:/newFile.txt");
		System.out.println("Create file: " + f.createNewFile());
		System.out.println("Filename: " + f.getName());
		System.out.println("Length: " + (f.length()) + "bytes");
		System.out.println("Last modified timesptamp: " + f.lastModified());
		System.out.println("File is renamed to hello.txt: "
				+ f.renameTo(new File("C:/hello.txt")));
	}
}
Advertisement

Related Tags for Java file object:


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: June 5, 2006

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com