两种办法,使用java.net.URL或者 System.getProperty("user.dir")
使用java.net.URL比较复杂,但存在中文问题
public
static
String getRealPath(String filename)
...
{
String path="";
Class theClass=TestHelloWorld.class;
java.net.URL u= theClass.getResource(filename);
return u.getPath();
}
String path="";
Class theClass=TestHelloWorld.class;
java.net.URL u= theClass.getResource(filename);
return u.getPath();
}