[英]how to read htm file inside a zip file?
我有一個包含Index.htm的zip文件。 我應該閱讀Index.htm的內容,並在其中找到一個日期( 2011年12月 ),並使用該日期創建一個目錄,然后在該目錄中提取zip文件。
這是html文件:
<HTML>
<HEAD></HEAD>
<BODY>
<A Name="TopOfPage"></A>
<TABLE Width="100%" Border="0" CellPadding="0" CellSpacing="0">
<TR>
<TD Width="30%"><A HRef="HeaderTxt/HetBCFI.htm">Het B.C.F.I.</A></TD>
</TR>
</TABLE>
<TABLE Width="100%" Border="0" CellPadding="0" CellSpacing="0">
<TR>
<TD RowSpan="2" Width="10"></TD>
<TD Width="70%"><STRONG><FONT Face="Arial" Size="2">Gecommentarieerd Geneesmiddelenrepertorium</FONT></STRONG></TD>
<TD Width="29%" Align="Right" Class= "Datum">
December 2011
</TD>
<TD Rowspan="2" Width="10"></TD>
</TR>
</TABLE> </BODY> </HTML>
嘗試這個,
獲得日期字符串后,創建所需的目錄。
編輯 :要刪除
,您可以執行以下操作之一,
使用包含
的字符串創建另一個文檔元素
並執行以下操作
document.select(":containsOwn(\ )").remove();
(從這里拍攝)
使用關注(假設您要清除的字符串是htmlString
)
Jsoup.parse(htmlString).text();
使用String的replaceAll()
函數擺脫
。
幾個步驟:
這假定您要查找的日期始終在文本節點中。
這是我使用的正確的最終代碼:多謝您提供有用的提示
public static String getDateWithinHtmlInsideZipFile(File archive) {
ZipFile zp = new ZipFile(archive);
InputStream in = zp.getInputStream (zp.getEntry ("Index.htm"));
Document doc = Jsoup.parse(in, "UTF-8", "");
return doc.body().getElementsByClass("Datum").text().trim();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.