java文件整理(四)--jar文件操作

 

  
  
  
  
  1. package com.tw.jarfile;  
  2. import java.io.IOException;     
  3. import java.net.JarURLConnection;     
  4. import java.net.URL;     
  5. import java.util.Enumeration;     
  6. import java.util.Map;     
  7. import java.util.Map.Entry;     
  8. import java.util.jar.Attributes;     
  9. import java.util.jar.JarEntry;     
  10. import java.util.jar.JarFile;     
  11. import java.util.jar.Manifest;  
  12.  
  13. /**  
  14.  * <p>jar文件操作</p>��jar���л�������ļ�  
  15.  * @author tw 2010-05-09  
  16.  *  
  17.  */ 
  18. public class Fuk {  
  19.     /**  
  20.      * @param args  
  21.      */ 
  22.     public static void main(String[] args) {  
  23.         // TODO Auto-generated method stub  
  24.         try {     
  25.             JarFile j = new JarFile("E:/prj_wangwin/prj_admin_bak/alliance/WEB-INF/lib/axis.jar");     
  26.             Enumeration<JarEntry> entries = j.entries();     
  27.             while (entries.hasMoreElements()) {     
  28.                 JarEntry je = entries.nextElement();     
  29.                 System.out.println(je.getName());     
  30.             }  
  31.             System.out.println();     
  32.             Manifest manifest = j.getManifest();     
  33.             Attributes mainAttributes = manifest.getMainAttributes();     
  34.             for (Entry<Object, Object> e : mainAttributes.entrySet()) {     
  35.                 System.out.println(e.getKey() + ":" + e.getValue());     
  36.             }     
  37.             System.out.println();     
  38.             System.out.println();     
  39.             System.out.println();     
  40.             Map<String, Attributes> entries2 = manifest.getEntries();     
  41.             for (Entry<String, Attributes> e : entries2.entrySet()) {     
  42.                 System.out.println(e.getKey() + ":" + e.getValue());     
  43.             }     
  44.      
  45.             System.out.println();     
  46.             URL url = new URL("jar:file:/E:/prj_wangwin/prj_admin_bak/alliance/WEB-INF/lib/axis.jar!/");     
  47.             JarURLConnection jarConnection = (JarURLConnection) url     
  48.                     .openConnection();     
  49.             Manifest m = jarConnection.getManifest();     
  50.             Attributes aaa = m.getMainAttributes();     
  51.             for (Entry<Object, Object> e : aaa.entrySet()) {     
  52.                 System.out.println(e.getKey() + ":" + e.getValue());     
  53.             }     
  54.     
  55.             System.out.println();     
  56.             System.out.println();     
  57.             System.out.println();     
  58.     
  59.         } catch (IOException e) {     
  60.             e.printStackTrace();     
  61.         }    
  62.  
  63.     }   
  64.  
  65.  
  66. }  

 

你可能感兴趣的:(java,职场,jar,休闲)