Advertisements
Home > Java > Java Program to display file attributes like isfile(), exist() etc – Q32

Java Program to display file attributes like isfile(), exist() etc – Q32


Q32: Java Program to display file attributes like isfile(), exist() etc

import java.io.*;

class file_attrib{

	static void p(String s){
		System.out.println(s);
	}

	public static void main(String args[]){
		File f1 = new File("fact_rec.java");
		p("File name: " + f1.getName());
		p("path: " + f1.getPath());
		p("Abs Path :" + f1.getAbsolutePath());
		p("Parent: "+ f1.getParent());
		p(f1.exists() ? "exists" : "dose not exist");
		p(f1.canWrite() ? "is writable" : "is not writable");
		p(f1.canRead() ? "is readable" : "is not readable");
		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");
		p("File last modified: " + f1.lastModified());
		p("File size: " + f1.length() + " Bytes");
		}
}

… from College notes (BCA/MCA assignments):


Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: