Pin It

Program to demonstrate how to display File information in Java ?.

Introduction
In this section of blog, we will look into a simple program that will demonstrate how to display File information in Java. The methods used here are defined in File class present in java.io.* package. For more details of this method read my blog post : Creating objects and methods list of File class in Java

package com.hubberspot.file.example;

import java.io.*;

/**
 *
 * @author Jontymagicman
 */

public class FileInformation {
  public static void main(String[] args){
        
    File file = new File("E:\\notepad.txt");
        
    System.out.println("File Name : "+ file.getName()); 
 
 System.out.println("File last modified : "+ file.lastModified()); 
 
 System.out.println("File size : " + file.length() + " Bytes"); 
 
 System.out.println("Path : "+file.getPath()); 
 
 System.out.println("Abs Path : "+file.getAbsolutePath()); 
 
 System.out.println("Parent : "+ file.getParent()); 
 
    System.out.println(file.exists() ? +
+"File exists":"File does not exist"); 
 
    System.out.println(file.canWrite() ? +
+"File is writable" : "File is not writable"); 
 
 System.out.println(file.canRead() ? +
+"File is readable" : "File is not readable"); 
 
    System.out.println(file.isHidden() ? +
+"File is hidden" : "File is not hidden"); 
 
 System.out.println(file.isDirectory() ? +
+"Is a directory" : "Is not a directory"); 
 
    System.out.println(file.isFile() ? +
+"Is a file" : "Is not a file"); 
 
    System.out.println(file.isAbsolute() ? +
+"File is absolute" : "File is not absolute" );
        
  }
    
}

Output of the program




Please Give Us Your 1 Minute In Sharing This Post!
SOCIALIZE IT →
FOLLOW US →
SHARE IT →
Related Posts Plugin for WordPress, Blogger...

Post your related queries below ...

comments powered by Disqus
Powered by Blogger.
 
© 2012 Learn Java by Examples Template by Hubber Spot