如何在 zip 存档中读取二进制文件(获取字节数组)?我正在使用TrueZip。
我的例子:
import de.schlichtherle.truezip.file.TFile;
import java.util.HashMap;
public class Archive {
private final TFile archive;
// String in HashMap represents filename ( eg. MyTextFile.txt )
private final HashMap<String, TFile> entries = new HashMap<>();
public Archive( String path ) {
this.archive = new TFile(path);
this.listEntries( archive.getAbsolutePath() );
}
// lists all files
private void listEntries( String pathToZipFile ) {
TFile archive = new TFile( pathToZipFile );
for ( TFile listFile : archive.listFiles() ) {
if ( listFile.isDirectory() ) {
listEntries(listFile.getAbsolutePath());
} else {
entries.put(listFile.getName(), listFile);
}
}
}
public byte[] getBytes( String key ) {
TFile file = entries.get(key);
// ...
}
我正在寻找这样的东西,但对于 TFile / TPath:
Files.readAllBytes( file.toPath() );