Eclipse生成Jar导入外部文件|程序搁浅在这里2小时,我怒了!

实在不想再看那段代码,桌面都给它糟蹋的不成样子了 
 
 
 
 
 
主要是这个函数叫人蛋疼  Class.getResource(String str)
连我一个小小的要求都不能满足,恨死了!
PS:程序完全正确,Eclipse下运行,成功,
对XML文件读取 修改后,另存为新的hzlzh_07.xml 在C:/下
 

 

关键代码如下:
Document document=domBuilder.parse(
          new File(hzlzh_07.class.getResource("system.xml").getFile()));
包资源管理器如图:[hzlzh_07就是类的名字,用来定位当前文件包]
 
 
我就不知道为什么生成包后就访问不到XML文件了。。。!
下面是生成包的结构图!
 
 
 
———————–我是分割线—————
另外我也试过下面这个方法获得路径
import java.lang.*;
public class A
{
   public static void main(String[] args)
   {
     String s = A.class.getResource("文件名").toString().substring(5);
     System.out.println(s);
   }
}//红色部分substring(5); 是不可缺少的,他可以将你得到的路径前面无效部分去掉
//最好自己动手跟踪下,看看path值!
 PS:一般情况最好用  /  来写路径这样可以减少错误,从本身的根节点寻址。当然是经验之谈啦!
版权所有© HzlzH | 本文采用 BY-NC-SA 进行授权
转载需注明 转自: 《Eclipse生成Jar导入外部文件|程序搁浅在这里2小时,我怒了!

随机文章

{ Leave a Reply ? }

  1. kangzj China Mozilla Firefox Windows

    不能着急,调程序就得慢慢来

  2. 高血压饮食 China Internet Explorer Windows

    我笑笑

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

:wink: :twisted: :roll: :oops: :mrgreen: :lol: :idea: :evil: :cry: :arrow: :?: :-| :-x :-o :-P :-D :-? :) :( :!: 8-O 8)