A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 王贺 中级黑马   /  2013-11-27 13:57  /  1163 人查看  /  5 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

public static void main(String[] args) throws IOException {
       File file = new File("d.txt");//错误的 //File file = new File("H:\\d.txt");正确的

     System.out.println(file.getAbsolutePath());
   if(!file.getParentFile().exists()){
    file.getParentFile().mkdirs();
   }else{
    System.out.println("oh,yse !");
   }
  }
错误显示:
in thread "main" java.lang.NullPointerException
at thread.Test12.main(Test12.java:22)


用File file = new File("H:\\d.txt");却正确,求指导

5 个回复

倒序浏览
File file = new File("d.txt");这样定义File类,会到当前项目下去查找a.txt文件。你将这个文件复制到项目下就可以了。File file = new File("H:\\d.txt");这个使用了绝对路径,这样它会到你的H盘下找a.txt文件,找到就不报异常。
回复 使用道具 举报
同学、问题已经解决了吗?
如果没有、就去新版28期问吧,26~27已经结束了。开班了!
http://bbs.itheima.com/forum-165-1.html

如果问题已经解决,请及时修改主题为“提问结束”。
修改主题的方法链接
http://bbs.itheima.com/thread-89313-1-1.html
如果没有解决,可能你的问题问得不够清楚。可以重新发问的哦~
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马