当前位置: 代码迷 >> J2EE >> File file=new File(""); file的父目录替什么是null
  详细解决方案

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

热度:135   发布时间:2016-04-19 21:57:48.0
File file=new File("."); file的父目录为什么是null

file.getParent();为什么是null呢,当前目录是有父目录的
------解决方案--------------------
File file=new File(".")获取的是当前目录的相对路径,要先将其转为绝对路径,然后再获取其父目录
File file = new File(".");
System.out.println(file.getPath());
System.out.println(file.getCanonicalFile().getParent());
  相关解决方案