Jsp Tutorial Directory file operations
File file1 = new file ("c: tempmynote.txt"); // in windows
File file2 = new file ("/tmp/mynote.txt"); // in linux/unix
Check file path
Import java. io. file;
Public class mainclass {
Public static void main (string [] ){
File myfile = new file ("c:" + file. separator + "jdk1.5.0" +
File. separator, "file. java ");
System. out. println (myfile. getname ());
System. out. println (myfile. getpath ());
}
}
Obtain remote images
Import java. io. file;
Import java.net. uri;
Public class mainclass {
Public static void main (string [] a) throws exception {
File remotefile = new file (new uri ("file: // index.htm "));
}
}
Parent Directory
Import java. io. file;
Public class mainclass {
Public static void main (string [] ){
File myfile = new file ("c:" + file. separator + "jdk1.5.0" +
File. separator, "file. java ");
System. out. println (myfile. getparent ());
System. out. println (myfile );
}
}
Determine if it is a directory
Import java. io. file;
Public class mainclass {
Public static void main (string [] ){
File myfile = new file ("c:" + file. separator + "jdk1.5.0" +
File. separator, "file. java ");
System. out. println (myfile. isdirectory ());
}
}
Is it a file?
Import java. io. file;
Public class mainclass {
Public static void main (string [] ){
File myfile = new file ("c:" + file. separator + "jdk1.5.0" +
File. separator, "file. java ");
System. out. println (myfile. isfile ());
}
}