All Methods related to File

//Collected 

import java.io.File;

public class Main{
    static void p(String s){
        System.out.println(s);
    }
    public static void main(String args[]){
        File f = new File("C:/myfile.txt");
        p("File Name: " + f.getName());
        p("Path: " + f.getPath());
        p("Abs Path: " + f.getAbsolutePath());
        p("Parent: " + f.getParent());
        p(f.exists()?"exit":"does not exist");
        p(f.canWrite()? "is writeable" : "is not writeable");
        p(f.canRead()? "is readable" : "is not readable");
        p(f.isDirectory()? "Directory" : "not a Directory");
        p(f.isFile()? "File" : "Not a file");
        p(f.isAbsolute()?"absolute": "Not absolute");
        p("File last Modified: " + f.lastModified());
        p("File size: " + f.length() + "Bytes");
    }
}

No comments:

Post a Comment