Wednesday, 19 December 2012

Aim: Write a Java program that reads a file name from the user, then displays information about whether the file exists, whether the file is readable, whether the file is writable, the type of file and the length of the file in bytes.



import java.io.*;
import java.util.*;
class filedemo
{
public static void main(String args[])
{
File f=new File(args[0]);
System.out.println("name :"+f.getName());
System.out.println("path:"+f.getAbsolutePath());
System.out.println("exists:"+f.exists());
System.out.println("is file:"+f.isFile());
System.out.println("is dir:"+f.isDirectory());
System.out.println("read :"+f.canRead());
System.out.println("write:"+f.canWrite());

long l=f.lastModified();
Date d=new Date(l);
int date=d.getDate();
int month=d.getMonth();
int year=d.getYear();
int hh=d.getHours();
int mm=d.getMinutes();
int ss=d.getSeconds();
System.out.println(date+"/"+(month+1)+"/"+(1900+year));
System.out.println(hh+":"+mm+":"+ss);
}
}

No comments:

Post a Comment