Pages

Ads 468x60px

Monday 17 December 2012

FileInputstream class



12.      WAJP that reads on file name from the user then displays information about whether the file exists, whether the file is readable/writable, the type of file and the length of the file in bytes and display the content of the using FileInputStream class.
Program:
                                           Download link to Fileinputstream

import java.io.File;
import java.lang.String;
import java.util.*;

class FileDemo
{
  static void file(String s)
  {
    System.out.println(s);
  }
 public static void main(String args[])
 {
   File f1=new File(args[0]);
  
   System.out.println("File Name:"+f1.getName());
  
   System.out.println("Path:"+f1.getPath());
  
   System.out.println("Abs Path:"+f1.getAbsolutePath());
  
   System.out.println("Parent:"+f1.getParent());
  
   System.out.println(f1.exists()?"exists":"does not exist");
  
   System.out.println(f1.canWrite()?"is writable":"is not writable");
  
   System.out.println(f1.canRead()?"is readable":"is not readable");
  
   System.out.println("is"+(f1.isDirectory()?"":"not"+"a directory"));
  
   System.out.println(f1.isFile()?"is normal file":"might be a named pipe");
  
   System.out.println(f1.isAbsolute()?"is absolute":"is not absolute");
  
   System.out.println("File last modified:"+f1.lastModified());
  
   System.out.println("file size:"+f1.length()+"Bytes");
 
  }
 
}    

0 comments:

Post a Comment

 

Sample text

Sample Text

Sample Text