<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    常用鏈接

    統計

    最新評論

    從jar中讀取文件

    Sample1,利用Menifest文件讀取jar中的文件
    /*
    1.文件目錄
    test--
         --a.text
         --b.gif

    2. Menifest文件內容:
    Manifest-Version: 1.0
    abc: test/a.txt
    iconname: test/Anya.jpg
    注意:manifest.mf文件最后一行要打一回車
    Another Notification:
    如果manifest文件內容是:
    Manifest-Version: 1.0
    Main-Class: com.DesignToolApp
    Class-path: lib/client.jar lib/j2ee.jar
    在MANIFEST.MF文件的最后,要留兩個空行(也就是回車),才可以識別到Class-Path這一行,如果只有一個空行,那么只識別到Main-Class這一行。Class-Path中的庫名用空格格開,使用和jar包相對的路徑,發布時把jar包和其他用到的類庫一起交給用戶就可以了。


    3.打jar包
    test.jar
    */ 
    String iconpath = jar.getManifest().getMainAttributes().getValue("abc");
        InputStream in = jar.getInputStream(jar.getJarEntry(iconpath));
         //Image img = ImageIO.read(in);
        InputStreamReader isr =  new InputStreamReader(in);
           BufferedReader reader = new BufferedReader(isr);
           String line;
           while ((line = reader.readLine()) != null) {
               System.out.println(line);
           }
           reader.close();

    Sample2,讀取JAR 文件列表及各項的名稱、大小和壓縮后的大小

    public class JarFileInfoRead {
     public static void main (String args[])
      throws IOException {
      String jarpath="d://temp//test.jar";
      JarFile jarFile = new JarFile(jarpath);
      Enumeration enu = jarFile.entries();
      while (enu.hasMoreElements()) {
          process(enu.nextElement());
      }
    }

    private static void process(Object obj) {
      JarEntry entry = (JarEntry)obj;
      String name = entry.getName();
      long size = entry.getSize();
      long compressedSize = entry.getCompressedSize();
      System.out.println(name + "\t" + size + "\t" + compressedSize);
    }
    }

    Sample3,讀取JAR中 文件的內容
    public class JarFileRead {
        public static void main (String args[])
            throws IOException {
          String jarpath="d://temp//test.jar";
          JarFile jarFile = new JarFile(jarpath);
            Enumeration enu = jarFile.entries();
            while (enu.hasMoreElements()) {
             JarEntry entry = (JarEntry)enu.nextElement();
                String name = entry.getName();
                //System.out.println(name);
                if(name.equals("test/a.txt")){
                InputStream input = jarFile.getInputStream(entry);
                process(input);
                }
            }       
            jarFile.close();
        }
        private static void process(InputStream input)
            throws IOException {
            InputStreamReader isr =
                new InputStreamReader(input);
            BufferedReader reader = new BufferedReader(isr);
            String line;
            while ((line = reader.readLine()) != null) {
                System.out.println(line);
            }
            reader.close();
        }
    }

    posted on 2008-03-06 12:51 九寶 閱讀(899) 評論(0)  編輯  收藏 所屬分類: Java

    主站蜘蛛池模板: 国产av无码专区亚洲av桃花庵| 日本免费电影一区| 久久久久久久99精品免费| 爱丫爱丫影院在线观看免费| 99视频在线看观免费| 午夜影视在线免费观看| 亚洲av无码乱码在线观看野外| 亚洲精品乱码久久久久66| 亚洲AV无码成人专区| 真正全免费视频a毛片| 中文字幕久无码免费久久| 无码精品A∨在线观看免费| 免费在线观看你懂的| 99久久精品国产亚洲| 黄色a三级免费看| 男女超爽刺激视频免费播放| 亚洲国产成人精品无码区在线网站| 人与动性xxxxx免费| 性生交片免费无码看人| 久久久亚洲精品无码| 日韩精品亚洲专区在线影视| 1000部啪啪毛片免费看| 亚洲AV无码一区二区三区在线观看| 免费一级毛片在线播放视频免费观看永久 | 国产精品视频白浆免费视频| 日本大片在线看黄a∨免费| 国产亚洲人成在线影院| 亚洲综合精品香蕉久久网| 在线观看日本亚洲一区| 无码A级毛片免费视频内谢| 亚洲一区二区三区免费在线观看 | 亚洲色婷婷综合久久| 黄页免费视频播放在线播放| 日日噜噜噜噜夜夜爽亚洲精品 | 久久久久av无码免费网| 亚洲AV福利天堂一区二区三 | 在线永久看片免费的视频| 亚洲人成在线影院| 三年片免费观看大全国语| 666精品国产精品亚洲| 日本免费中文字幕|