在代码的最后一部分,我打印了读者给我的内容。但这只是假的,我哪里错了?
public static void read_impl(File file, String targetFile) {
// Create zipfile input stream
FileInputStream stream = new FileInputStream(file);
ZipInputStream zipFile = new ZipInputStream(new BufferedInputStream(stream));
// Im looking for a specific file/entry
while (!zipFile.getNextEntry().getName().equals(targetFile)) {
zipFile.getNextEntry();
}
// Next step in api requires a reader
// The target file is a UTF-16 encoded text file
InputStreamReader reader = new InputStreamReader(zipFile, Charset.forName("UTF-16"));
// I cant make sense of what this print
char buf[] = new char[1];
while (reader.read(buf, 0, 1) != -1) {
System.out.print(buf);
}
}
最佳答案
我猜你出错的地方是相信该文件是 UTF-16 编码的。
如果不解码,能否显示一些初始字节值?
关于java - 用Java从ZIP压缩包中提取UTF-16编码的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2131484/