docx ファイルの inputStream があり、docx 内にある document.xml を取得する必要があります。
ZipInputStream を使用してストリームを読み取っていますが、コードは次のようなものです
ZipInputStream docXFile = new ZipInputStream(fileName);
ZipEntry zipEntry;
while ((zipEntry = docXFile.getNextEntry()) != null) {
if(zipEntry.getName().equals("word/document.xml"))
{
System.out.println(" --> zip Entry is "+zipEntry.getName());
}
}
ご覧のとおり、zipEntry.getName の出力は、ある時点で「word/document.xml」になります。この document.xml をストリームとして渡す必要があります。.getInputStream の呼び出しでこれを簡単に渡すことができる ZipFile メソッドとは異なり、この docXFile をどのように行うことができるのでしょうか?
前もってありがとう、ミーナクシ
@Update: このソリューションの出力を見つけました:
ZipInputStream docXFile = new ZipInputStream(fileName);
ZipEntry zipEntry;
OutputStream out;
while ((zipEntry = docXFile.getNextEntry()) != null) {
if(zipEntry.toString().equals("word/document.xml"))
{
System.out.println(" --> zip Entry is "+zipEntry.getName());
byte[] buffer = new byte[1024 * 4];
long count = 0;
int n = 0;
long size = zipEntry.getSize();
out = System.out;
while (-1 != (n = docXFile.read(buffer)) && count < size) {
out.write(buffer, 0, n);
count += n;
}
}
}
この出力ストリームを入力ストリームに変換するための基本的な API があるかどうか疑問に思っていますか?