我迭代了一些我知道是文本文件的 JarEntries。但是当我找到它时如何将 JarEntry 转换为字符串呢?
JarEntry jarEntry = connection.getJarEntry();
JarFile archive = connection.getJarFile();
Enumeration<JarEntry> entries = archive.entries();
while (entries.hasMoreElements()) {
JarEntry entry = entries.nextElement();
String name = jarEntry.getName();
if (entry.getName().startsWith(name) && !entry.isDirectory()) {
// Convert this entry to a string
}
}
编辑:
我认为应该这样做:
InputStream inputStream = archive.getInputStream(entry);
StringWriter writer = new StringWriter();
IOUtils.copy(inputStream, writer, "UTF-8");
String theString = writer.toString();
System.out.println(theString);