Package File;import Java.io.file;public class FileTest1 {public static void main (string[] args) {//TODO auto-generated Me Thod stub/* just establish a connection with this file, not to see if the file exists */string parentpath= "E:/backup"; String name= "Expdat. DMP ";//Use relative path to build file Object file Src=new file (parentpath,name);//file (file parent,string child) // Creates a new file object based on the parent abstract pathname and child pathname string file Src1=new file (parentpath), name),//file (String parent,string Child) /////Create a new File Object System.out.println (Src.getname ()) based on the parent pathname string and the child pathname string;//file (string parent)// The absolute path to build files file src2=new ("E:/backup/2.jpg"); System.out.println (Src2.getpath ());//File Src3=new file ("2.jpg") without a drive letter; System.out.println (Src3.getpath ()); System.out.println (Src3.getabsolutepath ()); }}
Run results
Expdat. DMPE:\BACKUP\2.JPG2.JPGF:\J2EE Operation \tt\2.jpg
Constructing a file object with relative paths and absolute paths