[英]Getting 7-Zip information in java
I'm using 7-zip in my java program to zip several files and folders (mostly games) to several 7-zip files.我在我的 java 程序中使用 7-zip 将几个文件和文件夹(主要是游戏)压缩到几个 7-zip 文件中。
As an example:举个例子:
test1.txt and test1 -> test1.7z
test2.txt and test2 -> test2.7z
The zipping is no problem, but since the folders can be really large I wanted to include 2 progress bars (so the user can check how far the zip-process is).压缩没有问题,但由于文件夹可能非常大,我想包括 2 个进度条(以便用户可以检查压缩过程有多远)。
Currently I have the following code (which works so far), but how can I get the percentage of the zipping process?目前我有以下代码(到目前为止有效),但是如何获得压缩过程的百分比? The current output just gives back the start and result of the zipping process.
当前输出只返回压缩过程的开始和结果。
private void runZipCommand() {
ProcessBuilder pb = null;
ArrayList<Game> game = getGames();
for (Game g : game) {
pb = new ProcessBuilder(makeZipString(g, false));
pb.redirectError();
try {
Process p = pb.start();
InputStream is = p.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line;
while((line = br.readLine()) !=null){
System.out.println(line);
}
System.out.println("Exited with: " + p.waitFor());
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
private String makeZipString(Game g, boolean batch) {
String programzip = "";
String gametitle = "";
String restfiles = "";
programzip = "\"" + sevenPath + "\\7z.exe\" " + ZIPCOMMANDS;
if (batch) {
gametitle = " \"" + g.getName().replaceAll("[_[^\\w\\däüöÄÜÖ\\+\\- ]]", "") + ".7z\" ";
} else {
gametitle = " \"" + backupPath.toString() + "\\" + g.getName().replaceAll("[_[^\\w\\däüöÄÜÖ\\+\\- ]]", "")
+ ".7z\" ";
}
restfiles = "\"" + g.getAppmanifest() + "\" \"" + steamUtil.getInstallDir() + "\\" + g.getDir() + "\"";
String s = programzip + gametitle + restfiles;
return s;
}
Is there any way to get the percentage of how far the single process (zipping test1.7z) is?有没有办法获得单个进程(压缩 test1.7z)的百分比?
If you need more information, I try to add it as fast as possible.如果您需要更多信息,我会尽量尽快添加。
Thanks for your answers.感谢您的回答。
LevKaz列夫卡兹
I think I solved my problem now.我想我现在解决了我的问题。
My "old" zip-command had following commands and switches:我的“旧”zip 命令具有以下命令和开关:
7z.exe a -t7z -m0=LZMA2 -mx9 -mmt=2
After checking out the 7-zip.chm, I found out, that I can change the output stream via switch:在查看 7-zip.chm 后,我发现我可以通过 switch 更改输出流:
-bs
After changing the output streams to the following将输出流更改为以下内容后
7z.exe a -t7z -m0=LZMA2 -mx9 -mmt=2 -bso0 -bse2 -bsp1
I can extract the progress from my BufferedReader.我可以从我的 BufferedReader 中提取进度。
Anyway, thanks to all who visited my question and special thanks to @DavidS for linking in the other question which led me to the right point.无论如何,感谢所有访问我的问题的人,并特别感谢@DavidS 链接到另一个问题,这让我找到了正确的观点。
EDIT:编辑:
This also is going well while extracting a *.7z file.这在提取 *.7z 文件时也很顺利。 Use the following command:
使用以下命令:
7z.exe x -bso0 -bse2 -bsp1 archive.7z -aoa -o"c:\OutputPath"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.