Author: gnuhpc
Source: http://www.cnblogs.com/gnuhpc/
File Path:
Import java. Io. file;
Public class filepath {
Public static void main (string Arg []) {
String pname1 =
File. Separator + "stuff" +
File. Separator + "VTC" +
File. Separator + "java6" +
File. SERVER + "1204 ";
System. Out. println (pname1 );
String pname2 =
File. Separator + "stuff" +
File. Separator + "bin ";
System. Out. println (pname2 );
String Path = pname1 + file. pathseparator + pname2;
System. Out. println (PATH );
}
}
Obtain the file path information from the file name:
Import java. Io. file;
Import java. Io. ioexception;
Public class filenames {
Public static void main (string Arg []) {
File file;
Try {
File = new file ("filenames. Java ");
System. Out. println ("name:" + file. getname ());
System. Out. println ("parent:" + file. getparent ());
System. Out. println ("Path:" + file. getpath ());
System. Out. println ("absolute path:" + file. getabsolutepath ());
System. Out. println ("canonical path:" + file. GetCanonicalPath ());
System. Out. println ();
File = new file (
File. Separator + "home" +
File. Separator + "Doc" +
File. Separator + "VTC" +
File. Separator + "java6" +
File. SERVER + "1204 ");
System. Out. println ("name:" + file. getname ());
System. Out. println ("parent:" + file. getparent ());
System. Out. println ("Path:" + file. getpath ());
System. Out. println ("absolute path:" + file. getabsolutepath ());
System. Out. println ("canonical path:" + file. GetCanonicalPath ());
System. Out. println ();
File = new file (".");
System. Out. println ("name:" + file. getname ());
System. Out. println ("parent:" + file. getparent ());
System. Out. println ("Path:" + file. getpath ());
System. Out. println ("absolute path:" + file. getabsolutepath ());
System. Out. println ("canonical path:" + file. GetCanonicalPath ());
System. Out. println ();
} Catch (ioexception e ){
System. Out. println (E );
}
}
}
File Information:
Import java. Io. file;
Import java. Io. ioexception;
Public class fileinfo {
Public static void main (string Arg []) {
File file;
If (Arg. length! = 1 ){
System. Out. println ("Usage: Java fileinfo <FILENAME> ");
Return;
}
Try {
File = new file (ARG [0]);
System. Out. println ("canonical path:" + file. GetCanonicalPath ());
System. Out. println ("is a normal file:" + file. isfile ());
System. Out. println ("is a directory:" + file. isdirectory ());
System. Out. println ("is a hidden file:" + file. ishidden ());
System. Out. println ("can execute:" + file. canexecute ());
System. Out. println ("can read:" + file. Canread ());
System. Out. println ("can write:" + file. canwrite ());
System. Out. println ("path name is absolute:" + file. isabsolute ());
System. Out. println ("length of file:" + file. Length ());
If (file. isdirectory ()){
String name [] = file. List ();
For (INT I = 0; I <name. length; I ++)
System. Out. println ("" + name [I]);
}
} Catch (ioexception e ){
System. Out. println (E );
}
}
}
Author: gnuhpc
Source: http://www.cnblogs.com/gnuhpc/