RT。
我之前的判断可以上传但是连CHM(看小说的朋友会知道)也能上传上去,后来我改成了
if(!ContentType.equals("application/x-zip-compressed")&&!ContentType.equals("application/x-rar-compressed"))
就不行了,只能上传ZIP的了,RAR的不能上传,是application/x-rar-compressed的问题吗?我这个是在网上搜的,应该没问题呀……

解决方案 »

  1.   

    那你就log一下上传rar文件时的ContentType嘛,看看是个啥
      

  2.   


    我刚看了 是application/octet-stream的,但是上传CHM的话也可以了,类型也是application/octet-stream的……我郁闷了!
      

  3.   

    额, 不知道ContentType时默认就是application/octet-stream
      

  4.   


    我现在正在加这个判断,只能2个方向都判断了,没办法了呀!o(︶︿︶)o 唉……判断后缀名太低级了吧!无奈呀……application/x-rar-compressed 的存在还有意义吗?
      

  5.   

    pulic class Test{   
      public static void main(String args[])   
      { try{   
      FileInputStream fi=new FileInputStream("压缩文件地绝对路径“);   
      ZipInputStream zin=new ZipInputStream(fi);   
      ZipEntry zip=null;   
      int a=0;   
      while((zin=zin.getNextEntry())!=null)   
      { FileOutputStream fou=new FileOutputStream("想要存放地目录”+zip.getName());   
      while((a=zin.read())!=-1)fou.write(a);   
      fou.flush();   
      fou.close();   
      }   
      zin.close();   
      }catch(IOException e){e.printStackTrace();}   
      }   
      }
      

  6.   

    public void unRarFile (String targetPath,String absolutePath)
    {
    //打开解压命令
    String cmd = "C:\\Program Files\\WinRAR\\WinRAR.exe";
    String unRarCmd = cmd + " x " + targetPath + " " + absolutePath;
    Runtime run = Runtime.getRuntime();
    try {
    Process proce = run.exec(unRarCmd);
    InputStreamReader isr = new InputStreamReader(proce.getInputStream());
    BufferedReader br = new BufferedReader(isr);
    String line = null;
    while((line=br.readLine()) != null)
    {
    String line_str = line.trim();
    if("".equals(line_str))
    {
    continue;
    }
    br.close();
    }
    } catch (IOException e) {
    // TODO 自动生成 catch 块
    e.printStackTrace();
    System.out.println("程序解压出现异常");
    }
    }
      

  7.   


    application/octet-stream
    是所有的,跟没判断一样……ZIP的判断可以用,但是RAR的就跟假货一样(application/x-rar-compressed )……现在弄的我先判断if(!ContentType.equals("application/x-zip-compressed")&&!ContentType.equals("application/x-rar-compressed"))
    再找文件后缀了,郁闷……又回去了……难道就不能只判断ContentType是不是ZIP、RAR吗?
      

  8.   

    哥们,你理解错了,我是上传文件只要上传RAR、ZIP2种,不过谢谢了!我下载生成ZIP的时候没问题……呵呵!