java.util.zip能实现分卷压缩吗? java.util.zip能实现分卷压缩吗?查了一天也没查到相关的资料,有了解的指点下,谢谢。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 说下自己目前的解决方法。通过命令行调用解压缩软件进行分卷压缩。缺点是服务器必须安装解压缩软件。服务器安装的是linux系统,安装的是7zip,分卷压缩为zip文件。下面为代码片段,排版贴上来有点乱,见谅。/** * @param srcfolderPath 源文件,文件或文件夹路径 * @param rarFilePath 压缩以后文件名 * @param volumneSize 分卷压缩包大小,以M为单位 * */ public static void compress7zipFile(String srcFilePath,String targetZipName,int volumneSize) throws IOException{ getFiles(srcFilePath); File listFile = File.createTempFile("fileList", ".tmp"); FileOutputStream fs = new FileOutputStream(listFile); try { StringBuffer fileList = new StringBuffer(); //拼接要打包的文件路径 for(String filePath:filePaths){ fileList.append(filePath+"\n"); } fs.write(fileList.toString().getBytes()); fs.flush();//使用Linux系统下命令将文件夹分卷压缩为zip文件,在windows系统下使用解压缩工具可直接解压 String command = "7za a "+ targetZipName+" "+ srcFilePath +" -v" +volumneSize +"m"; new CompressThread(command).start(); } catch (Exception e) { e.printStackTrace(); }finally{ fs.close(); }}public static void getFiles(String path) { File dir = new File(path); //根据文件地址创建File对象 File files[] = dir.listFiles(); //获取文件夹下的文件数组 for (File file:files ) { //循环遍历数组 if (file.isDirectory()) //判断文件是否是一个目录 getFiles(file.getAbsolutePath()); //如果为文件夹,继续执行本方法 else { filePaths.add(file.getAbsolutePath()); //将文件路径添加到集合中 } }} private static final class CompressThread extends Thread { private final String command; private CompressThread(String command){ this.command = command; } public void run(){ try { Runtime runtime = Runtime.getRuntime(); final Process process = runtime.exec(command.toString()+"\n"); process.getOutputStream().close(); } catch (Exception e) { e.printStackTrace(); } } } s2sh 搭建框架出现的问题啊??求助 请问一个javamail的问题,老是退回来怎么回事啊 如何用java代码调用xml里的数据,在页面上面显示 怎么控制显示的图片大小? 为什么我在XMLSPY中写的DTD文档总是提示is not well-formed呢? ActionServlet和Action是什么关系? 如何从数据库里取出大字段,反映到网页上,通过单击自动选择程序打开? j2ee j2me j2se之间有何区别? 一个发送字符的问题 struts中的标签问题 java使用jxl插件导出excel asix1.1调用webservice出差,请大师指点。。。。
通过命令行调用解压缩软件进行分卷压缩。缺点是服务器必须安装解压缩软件。
服务器安装的是linux系统,安装的是7zip,分卷压缩为zip文件。
下面为代码片段,排版贴上来有点乱,见谅。/**
* @param srcfolderPath 源文件,文件或文件夹路径
* @param rarFilePath 压缩以后文件名
* @param volumneSize 分卷压缩包大小,以M为单位
* */
public static void compress7zipFile(String srcFilePath,String targetZipName,int volumneSize) throws IOException{
getFiles(srcFilePath);
File listFile = File.createTempFile("fileList", ".tmp");
FileOutputStream fs = new FileOutputStream(listFile);
try {
StringBuffer fileList = new StringBuffer();
//拼接要打包的文件路径
for(String filePath:filePaths){
fileList.append(filePath+"\n");
}
fs.write(fileList.toString().getBytes());
fs.flush();
//使用Linux系统下命令将文件夹分卷压缩为zip文件,在windows系统下使用解压缩工具可直接解压
String command = "7za a "+ targetZipName+" "+ srcFilePath +" -v" +volumneSize +"m";
new CompressThread(command).start();
} catch (Exception e) {
e.printStackTrace();
}finally{
fs.close();
}
}
public static void getFiles(String path) {
File dir = new File(path); //根据文件地址创建File对象
File files[] = dir.listFiles(); //获取文件夹下的文件数组
for (File file:files ) { //循环遍历数组
if (file.isDirectory()) //判断文件是否是一个目录
getFiles(file.getAbsolutePath()); //如果为文件夹,继续执行本方法
else {
filePaths.add(file.getAbsolutePath()); //将文件路径添加到集合中
}
}
}
private static final class CompressThread extends Thread {
private final String command;
private CompressThread(String command){
this.command = command;
}
public void run(){
try {
Runtime runtime = Runtime.getRuntime();
final Process process = runtime.exec(command.toString()+"\n");
process.getOutputStream().close();
} catch (Exception e) {
e.printStackTrace();
}
}
}