Java to obtain the path of a file or folder.
Obtain the project path of the current class. If "/" File f = new File (this. getClass (). getResource (""). getPath (); System. out. println (f); Result: C: \ Documents ents % 20and % 20Settings \ Administrator \ workspace \ projectName \ bin \ com \ test to obtain the absolute path of the current class; Type 2: file directory = new File (""); // The parameter is null String courseFile = directory. getCanonicalPath (); System. out. println (courseFile); Result: C: \ Documents ents and Settings \ Administrator \ workspace \ projectName: Obtain the project path of the current class; Third: URL xmlpath = this. getClass (). getClassLoader (). getResource ("selected.txt"); System. out. println (xmlpath); Result: file:/C:/Documents % 20and % 20 Settings/Administrator/workspace/projectName/bin/selected.txtgets the selected.txt file path in the srcdirectory of the current project. Type 4: System. out. println (System. getProperty ("user. dir "); Result: C: \ Documents and Settings \ Administrator \ workspace \ projectName: System. out. println (System. getProperty ("java. class. path "); Result: C: \ Documents and Settings \ Administrator \ workspace \ projectName \ bin get the current project path