关于相对路径转换为绝对路径的问题

上善若火 2012-07-18 03:16:00


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()有什么区别呢 ? 什么时候用他们更合适呢 ?
...全文
112 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
brightyq 2012-07-18
  • 打赏
  • 举报
回复
getPath() 将抽象路径名转换为一个路径名字符串
getAbsolutePath() 返回抽象路径名的绝对路径名字符串。
如果此抽象路径名已经是绝对路径名,则返回该路径名字符串,这与 getPath() 方法一样

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧