2016-09-18 89 views
-4

我有一個名爲「mail.jar」的jar文件。我通過java代碼提取了jar文件。 現在我有清單文件出現在「D:/Test/META-INF/MANIFEST.MF」位置下。 This is the image of Manifest.mf file content。 任何我能夠通過FileReaderBufferedReader幫助讀取清單文件並將其打印到控制檯。 在清單文件中,低於規範r存在。 (1)清單-版本: (2)歸檔-版本: (3)創建-者: (4)出口型套餐:如何從jar文件中獲取Manifest.mf文件內容

現在我的疑問是如何獲得下的所有軟件包列表出口包裝:僅限標籤。 任何人都可以幫我嗎? 任何幫助將不勝感激。

O/P應顯示如下屏幕截圖。 Expected O/P screen shot

問候,AD

+0

請更改您的問題。目前還不清楚你想要做什麼或需要什麼。 –

+0

所羅門,你現在在這裏得到我的要求嗎?如果有任何疑問,請讓我知道如果您有任何疑問... – Abinash

+1

可能與[Manifest](https://docs.oracle.com/javase/7/docs/api/java/util/jar/Manifest .html)類。使用清單文件中的輸入流創建一個對象。 – PeterMmm

回答

1

嗨所羅門& PeterMmm, 感謝您的幫助。 現在我可以訪問特定屬性的清單文件內容。 下面是我使用的代碼片段: -

public class ReadmanifestFile { 
public String getManifestAttributes() throws IOException { 
    String value = null; 
    File file = new File("G:/AD/JAR_FILES/mail.jar"); 
    if (file.isFile()) { 
     JarFile jarfile = new JarFile(file); 
     Manifest manifest = jarfile.getManifest(); 
     Attributes attributes = manifest.getMainAttributes(); 
     value = attributes.getValue("Export-Package"); 
     String[] arr = value.split(";"); 
     for (int i = 0; i < arr.length; i++) { 
      System.out.println(arr[i]); 
     } 
    } 
    return value; 
} 

}

點擊下面的輸出上面的代碼片段: - Output

我認爲這是do.Plz正道讓我知道我是否可以用任何其他方式改進代碼片段。

關於, AD