public String decompression(String tat ,String zipPathName){
//tat 是压缩文件路径,zipPathName 是解压后保存路径
Runtime runtime = Runtime.getRuntime();
String textName = “”;
File testFile = new File(zipPathName);
String abnormal = “”;
if(!testFile .exists()) {
new File(zipPathName).mkdir();
String commandStr = ““C:\Program Files\WinRAR\winrar.exe” e “”
+ tat
+ “” “”
+ zipPathName+”"";
Process process;
try {
process = runtime.exec(commandStr);
process.waitFor();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
File newFile = new File(zipPathName);
File[] rawDataFiles = newFile.listFiles();
for(int rawDataIndex = 0;rawDataIndex<rawDataFiles.length;rawDataIndex++){
BufferedInputStream buffIn = null;
textName = rawDataFiles[rawDataIndex].getName();
}
return textName;
}
本文提供了一个使用WinRAR命令行工具进行文件解压缩的Java示例代码。该代码展示了如何通过Runtime.getRuntime().exec()执行外部命令来解压.zip文件,并将解压后的文件保存到指定目录。
3357

被折叠的 条评论
为什么被折叠?



