获取当前类的所在工程路径;
如果不加“/”
file f = new file(this.getclass().getresource("").getpath());
system.out.println(f);
结果:c:\documents%20and%20settings\administrator\workspace\projectname\bin\com\test
获取当前类的绝对路径;
第二种:file directory = new file("");//参数为空
string coursefile = directory.getcanonicalpath() ;
system.out.println(coursefile);
结果:c:\documents and settings\administrator\workspace\projectname
获取当前类的所在工程路径;
第三种:url xmlpath = this.getclass().getclassloader().getresource("selected.txt");
system.out.println(xmlpath);
结果:file:/c:/documents%20and%20settings/administrator/workspace/projectname/bin/selected.txt
获取当前工程src目录下selected.txt文件的路径
第四种:system.out.println(system.getproperty("user.dir"));
结果:c:\documents and settings\administrator\workspace\projectname
获取当前工程路径第五种:system.out.println( system.getproperty("java.class.path"));
结果:c:\documents and settings\administrator\workspace\projectname\bin
获取当前工程路径