File class Example

import java.io.File;
public class FileDemo1 
{
	public static void main(String[] args) 
	{
	try {
	File f2=new File("c:\\new.txt");
	if(f2.exists())
	{
		System.out.println("It is existing");
	}
	else
	f2.createNewFile();
	File f=new File("c:\\");
	String s[]=f.list();
	for(String s1:s)
	{
		String fname=s1;
		File f1=new File(f.getPath()+fname);	
		if(f1.isDirectory())
			System.out.println(s1+"\tis a directory");
		else if(f1.isFile())
			System.out.println(s1+"\tis a file");
		else
			System.out.println(s1+"\tis a not file or not  directory");
}	
} catch (Exception e) {
}
}
}

Download

Input and Output Stream in Java

Example FileOutputStream
Example FileInputStream
DataInput and Output Example
Object Serialization
Object Deserialization
Object Externalizable Example
Example java.io.File class
RandomAccessFile Example


Write your Comment

Name :
Email Id : [ We will not publish your email id ]
Your Comment : [ Maximum 200 chars ]
Enter Security code