The first type:
File F = new file (This.getclass (). GetResource ("/"). GetPath ());
System.out.println (f);
Results:
C:\Documents%20and%20Settings\Administrator\workspace\projectName\bin
Gets the project path where the current class is located;
If you do not add "/"
File F = new file (This.getclass (). GetResource (""). GetPath ());
System.out.println (f);
Results:
C:\Documents%20and%20Settings\Administrator\workspace\projectName\bin\com\test
Gets the absolute path of the current class;
The second type:
File directory = new file ("");//parameter is empty
String coursefile = Directory.getcanonicalpath ();
System.out.println (Coursefile);
Results:
C:\Documents and Settings\administrator\workspace\projectname
Gets the project path where the current class is located;
The third type:
URL Xmlpath = This.getclass (). getClassLoader (). GetResource ("Selected.txt");
System.out.println (Xmlpath);
Results:
File:/c:/documents%20and%20settings/administrator/workspace/projectname/bin/selected.txt
Gets the path to the Selected.txt file in the current project SRC directory
The fourth type:
System.out.println (System.getproperty ("User.dir"));
Results:
C:\Documents and Settings\administrator\workspace\projectname
Get current project path
The fifth type:
System.out.println (System.getproperty ("Java.class.path"));
Results:
C:\Documents and Settings\administrator\workspace\projectname\bin
Get current project path
Java file path