java runtime.exec(cmd) 提示Cannot run program "unzip": CreateProcess error=2,

大志强 2016-08-20 04:38:41
Exception in thread "main" java.io.IOException: Cannot run program "unzip": CreateProcess error=2, ?????????
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1041)
at java.lang.Runtime.exec(Runtime.java:617)
at java.lang.Runtime.exec(Runtime.java:450)
at java.lang.Runtime.exec(Runtime.java:347)
at cn.oumasoft.bc.FileDemo.main(FileDemo.java:64)
Caused by: java.io.IOException: CreateProcess error=2, ?????????
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(ProcessImpl.java:376)
at java.lang.ProcessImpl.start(ProcessImpl.java:136)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1022)
... 4 more


public static void main(String args[]) throws IOException{
//目的地文件夹
String destDir = "E:"+File.separator+"UP"+File.separator;

String fileName = "zhaopianshenhechuli";
String fileFullName=fileName+".zip";
String sourceFileDir = "F:"+File.separator+fileName;
String sourceFileDirName= sourceFileDir+".zip";
String destDirFulName =destDir+fileFullName;
System.out.println("文件上传开始:"+System.currentTimeMillis());
System.out.println("路径输出:"+ sourceFileDir);
//复习IO流
/**
* 字节流: InputStream OutputStream 主要操作对象为字节流 他们是字节流最大的父类
* InputStream OutputStream
* | |
* ( 如果想读一个文件的内容) ( 如果想对某个文件写出内容)
* FileInputStream FileOutputStream
*
*
*/
File sourceFile = new File(sourceFileDirName);
File destFile = new File(destDirFulName);
//字节输入流 省略了判断路径存在与否
FileInputStream fileInputStream = new FileInputStream(sourceFile);
InputStream inputStream = fileInputStream;
//字节输出流
OutputStream outpStream = new FileOutputStream(destFile);
//定义每次读取的大小
byte [] data = new byte[2048];
int temp = 0 ;
// read方法:Reads up to len bytes of data from the input stream into an array of bytes.
while((temp=inputStream.read(data))!=-1){
outpStream.write(data, 0, temp);
}
System.out.println("文件上传结束:"+System.currentTimeMillis());
System.out.println("开始解压文件:"+System.currentTimeMillis());
//此路不通,只能通过unzip方式解压了 调用本机cmd 进行解压
/*ZipFile zipfile = new ZipFile(destFile);
ZipEntry entry = zipfile.getEntry(fileFullName);
InputStream zipInputStream = zipfile.getInputStream(entry);*/
//String command="uzip -n -P " + unzipPwd +" "+zipFileName +" -d "+localDirectory ;
String command = "unzip -n " + destDirFulName + " -d " + destDir;
//String command ="unzip -n " +destDirFulName +" -d "+ destDir ;
Runtime runtime= Runtime.getRuntime();
Process process = runtime.exec(command);
System.out.println("文件解压结:"+System.currentTimeMillis());
}
...全文
1213 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
大志强 2016-08-25
  • 打赏
  • 举报
回复

51,411

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧