您的位置:程序门 -> java -> netbeans



nerbean生成jar的问题


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


nerbean生成jar的问题[已结贴,结贴人:shuanshuanzai]
发表于:2008-01-05 06:33:58 楼主
我用netbeans   编写一个小程序.其中需要读写f:\netbeansprojects\javaproject3\txt\info.txt这个文件.
怎么把info.txt加入到jar的文件中?
要不到了别的电脑上就提示找不到info.txt,
建立f:\netbeansprojects\javaproject3\txt\并把info.txt复制到目录下才能用.
发表于:2008-01-05 07:33:271楼 得分:0
读取jar里面的文件,不能采用   file   f   =   new   file("info.txt");这种方法哦

java code
url = new url(this.getclass().getclassloader().getresource("/text/info.txt"));

   
  有了url       剩下的,你自己搞吧!

源文  
发表于:2008-01-05 09:28:122楼 得分:0
不对哦  
new   url(this.getclass().getclassloader().getresource("/text/info.txt"));
url   没有这样的构造函数啊
发表于:2008-01-05 10:38:153楼 得分:0
路过
发表于:2008-01-05 10:55:254楼 得分:0
url   u   =   this.getclass().getclassloader().getresource("/file/1234.gif");
发表于:2008-01-06 08:00:295楼 得分:0
我怎么把info.txt加到jar里面阿?
生成jar的时候就自动进取了吗?
发表于:2008-01-06 08:26:496楼 得分:0
1   jar的时候你可以选择的,你把info.txt也放到那个目录就可以
2   如果不行,用第三方工具
3   简单方法,用winzip   /   winrar   打开.jar文件,把   info.txt   加入进去就行了!

提示:   jar采用的zip压缩算法。
发表于:2008-01-06 08:43:257楼 得分:0
晕了
url       u       =       this.getclass().getclassloader().getresource(filename);  

我的方法式这样的
public   void   readcustomers(string   filename)     throws   ioexception
      {    
              url       u       =       this.getclass().getclassloader().getresource(filename);   //怎么用到它阿??
            scanner   in   =   new   scanner(new   filereader(filename));
            boolean   done   =   false;
            while   (in.hasnext())
            {    
                  int   number   =   in.nextint();
                  int   pin   =   in.nextint();
                  customer   c   =   new   customer(number,   pin);
                  addcustomer(c);
            }
            in.close();
      }
发表于:2008-01-06 09:04:058楼 得分:20
你难道从不查api的文档吗?需要加强这方面的能力哦!


java code
scanner s = new scanner(u.openstream());


url


scanner


发表于:2008-01-06 09:28:149楼 得分:0
问题解决20送上


快速检索

最新资讯
热门点击