String path="/qh/cic/复习";
void test() throws Exception{
URL url=getClass().getResource(path);
File file=new File(url.toURI()); System.out.println(file.getPath());
System.out.println(file.getAbsolutePath());
}此时两句打印的结果相同,请教各位前辈,getPath()和getAbsolutePath()有什么区别呢 ? 什么时候用他们更合适呢 ?
void test() throws Exception{
URL url=getClass().getResource(path);
File file=new File(url.toURI()); System.out.println(file.getPath());
System.out.println(file.getAbsolutePath());
}此时两句打印的结果相同,请教各位前辈,getPath()和getAbsolutePath()有什么区别呢 ? 什么时候用他们更合适呢 ?
getAbsolutePath() 返回抽象路径名的绝对路径名字符串。
如果此抽象路径名已经是绝对路径名,则返回该路径名字符串,这与 getPath() 方法一样