<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<% String commandstr = "D:/WinRAR/Rar.exe x -t -o+ -p- C:/Users/guoshuai/workspace/LOGDEV/WebContent/LOG/Image/imageshow.rar C:/Users/guoshuai/workspace/LOGDEV/WebContent/LOG/Image/showrar/";
Process p ;
try {
p = Runtime.getRuntime().exec(commandstr); 
  while (true){ 
    if(p.waitFor() == 0) break;
  } 

catch (Exception e) {}
%>
</body>
</html>rar里面有5个图片,结果最多只能解压缩出一两个文件,之后rar.exe进程常驻,开始报错。
javaw.exe cpu占用97%

解决方案 »

  1.   

    LZ参考下:java解压zip文件(由于zip包使用Winra工具打的包,他的默认编码格式是gbk,所以在解压zip包中的中文文件明的文件的时候就会出现IllegalArguementException异常,解决方法就是在ZipInputStream 的 getUTF8String()方法中加上如下代码 String s=new String(b,off,len,"gbk"); return s;编译后将ZipInputStream 的class文件覆盖jdk\jre\rt.jar中java.util.zip包中的ZipInputStream.class)
     try {
    //   ZipInputStream zis = new ZipInputStream(new FileInputStream(
    //     "Archive.zip"));
       ZipInputStream zis = new ZipInputStream(new FileInputStream("e.zip"));
    //   ZipFile z=new ZipFile(Archive.zip);
       ZipEntry ze = null;   while ((ze=zis.getNextEntry()) != null) {    if (!ze.isDirectory()) {
         System.out.println(ze.getName());
    //     File child = new File(ze.getName());
         String filename=ze.getName();
         
         int at=filename.lastIndexOf("/");
         System.out.println(at);
         
         if(at!=-1)
         {
          String path=filename.substring(0, at);
          File pa=new File(path);
          
          pa.mkdirs();
          
          FileOutputStream outputStream = new FileOutputStream(pa+filename.substring(at));
          byte[] buffer = new byte[1024];
          int bytesRead = 0;      while ((bytesRead = zis.read(buffer)) > 0) {
           outputStream.write(buffer, 0, bytesRead);
          }
          outputStream.flush();
          outputStream.close();
         }else
         {
          FileOutputStream outputStream = new FileOutputStream(filename);
          byte[] buffer = new byte[1024];
          int bytesRead = 0;      while ((bytesRead = zis.read(buffer)) > 0) {
           outputStream.write(buffer, 0, bytesRead);
          }
          outputStream.flush();
          outputStream.close();
         }
        }
       }
       
       zis.close();
      } catch (Exception e) {
       e.printStackTrace();
      }
      

  2.   

    java 有解压和压缩的类 何必非要用winrar
      

  3.   

    Java那个貌似只能针对jar或者war或者zip之类的吧 没有针对RAR的