File(String directoryPath)
File(String directoryPath,String filename)
File(File dirObj,String filename)
File(URL uriObj)
File has many methods that can obtain the properties of file as use in this tutorial
CODING:
import java.io.File;class filedemo
{
static void p(String s)
{
System.out.println(s);
}
public static void main(String args[])
{
File f1 = new File("Pro java");
p("File Name:"+f1.getName());
p("Path:"+f1.getPath());
p("Abs Path:"+f1.getAbsolutePath());
p("Parent:"+f1.getParent());
p(f1.exists()?"exists":"does 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" : "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");
}
}
0 comments:
Post a Comment