File file=new File("."); file的父目录为什么是null

Super赛亚人 2014-04-17 12:23:26

file.getParent();为什么是null呢,当前目录是有父目录的
...全文
510 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
消极怠工 2014-04-21
  • 打赏
  • 举报
回复
不知道 具体的内部原因 不知道 是不是可以这样理解 . 是相对目录的跟目录
jiekou0704 2014-04-21
  • 打赏
  • 举报
回复
BeautfulSoup 2014-04-21
  • 打赏
  • 举报
回复
看看关于Java处理文件系统的原理就明白了啊,和类加载器有关系
ilmlife 2014-04-17
  • 打赏
  • 举报
回复
引用 1 楼 flyliuweisky547 的回复:
File file=new File(".")获取的是当前目录的相对路径,要先将其转为绝对路径,然后再获取其父目录
File file = new File(".");
		System.out.println(file.getPath());
		System.out.println(file.getCanonicalFile().getParent());
+1
flyliuweisky547 2014-04-17
  • 打赏
  • 举报
回复
File file=new File(".")获取的是当前目录的相对路径,要先将其转为绝对路径,然后再获取其父目录
File file = new File(".");
		System.out.println(file.getPath());
		System.out.println(file.getCanonicalFile().getParent());
Super赛亚人 2014-04-17
  • 打赏
  • 举报
回复
引用 3 楼 AWM_Godlike 的回复:
[quote=引用 1 楼 flyliuweisky547 的回复:] File file=new File(".")获取的是当前目录的相对路径,要先将其转为绝对路径,然后再获取其父目录
File file = new File(".");
		System.out.println(file.getPath());
		System.out.println(file.getCanonicalFile().getParent());
正解[/quote] 我不能理解,File file=File file=new File(".");应该是当前目录这个对象吧,为什么是相对路径,
-江沐风- 2014-04-17
  • 打赏
  • 举报
回复
. 的问题吧,当前目录
BeautfulSoup 2014-04-17
  • 打赏
  • 举报
回复
引用 1 楼 flyliuweisky547 的回复:
File file=new File(".")获取的是当前目录的相对路径,要先将其转为绝对路径,然后再获取其父目录
File file = new File(".");
		System.out.println(file.getPath());
		System.out.println(file.getCanonicalFile().getParent());
正解

67,515

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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