Program To Demonstrate How To Display File Information In Java ?.


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* 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;


* @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" );




For more of such hot topics read my other posts here :

Visit my new website

Article Written By jontymagicman

I am DInesh Varyani.

Last updated on 26-07-2016 258 0

Please login to comment on this post.
There are no comments yet.
What Do We Mean By Annotations In Java Programming Language ?.
How To Add Components And Event Handling To A Java Applet ?.