Monday, 13 July 2015

Java Programs[Important]

  1.   WRITE A JAVA PROGRAM that reads on file name from the user, then displays information about whether the file exists, whether the file is readable, wheteher the file is writable, the type of file and the length of the file in bytes.
  2.  
  3. Program :
  4.  
  5. import java.io.File; class FileDemo { static void p(String s)

  6.  {
  7.  System.out.println(s); 
  8. }
  9.  public static void main(String args[ ]) 
  10. {
  11.  File f1 = new File(args[0]);
  12.  p("File Name: " + f1.getName());
  13.  p("Path: " + f1.getPath());
  14.  p("Abs Path: " + f1.getAbsolutePath());
  15.  p("Parent: " + f1.getParent());
  16.  p(f1.exists() ? "exists" : "does not exist");
  17.  p(f1.canWrite() ? "is writeable" : "is not writeable"); p(f1.canRead() ? "is readable" : "is not readable");
  18.  p("is " + (f1.isDirectory() ? "" : "not" + " a directory")); p(f1.isFile() ? "is normal file" : "might be a named pipe"); p(f1.isAbsolute() ? "is absolute" : "is not absolute"); 
  19. p("File last modified: " + f1.lastModified());
  20.  p("File size: " + f1.length() + " Bytes"); 
  21. }
  22.