首页 新闻 赞助 找找看

java rar解压缩中文路径问题

0
[已解决问题] 解决于 2011-11-24 15:53

解压rar文件的时候如果路径里有中文就解压不了,请高手指点。。。

多谢了。。。

 1 package com.geap.gpwms.test;
2
3 import java.util.*;
4 import java.io.*;
5 import java.net.URLEncoder;
6
7 import org.apache.tools.zip.*;
8
9
10 public class ZipUtil
11 {
12 private static String unrarCmd = "d:\\Program Files\\WinRAR\\UnRar x ";
13
14
15
16 public static boolean unfile(String zipFile,String outFilePath,int mode){
17 boolean flag=false;
18 try{
19 File file = new File(zipFile);
20 String fileName = file.getName();
21 if(mode == 1)
22 {
23 outFilePath += File.separator; //文件当前路径下
24 }else{
25 outFilePath += File.separator+fileName.substring(0,fileName.length()-4)+File.separator;
26 }
27 File tmpFileDir = new File(outFilePath);
28 tmpFileDir.mkdirs();
29
30
31
32 unrarCmd += zipFile + " " + outFilePath;
33
34 try {
35 Runtime rt = Runtime.getRuntime();
36 Process p = rt.exec(unrarCmd);
37 BufferedReader br = new BufferedReader(new InputStreamReader(
38 p.getInputStream()));
39 BufferedReader br1 = new BufferedReader(new InputStreamReader(
40 p.getErrorStream()));
41 while ((br.readLine()) != null || br1.readLine() != null)
42 ;
43 p.waitFor();
44 flag=true;
45 } catch (Exception e) {
46 System.out.println(e.getMessage());
47 }
48 }
49
50 }catch(Exception e){
51 e.printStackTrace();
52 }
53 return flag;
54 }
55 public static void main(String[] args)
56 {
57 try
58 {
59 ZipUtil zip=new ZipUtil();
60
61 File file = new File("C:\\Documents and Settings\\Administrator\\桌面\\log.rar");
62 String zipFile=file.getAbsolutePath();
63 String outFilePath=file.getParentFile().getPath();
64 int mode=1;
65 //测试解压
66 zip.unfile(zipFile, outFilePath, mode);
67
68 }
69 catch (Exception e)
70 {
71 e.printStackTrace();
72 }
73
74 }
75
76 }
pm8:鉡的主页 pm8:鉡 | 初学一级 | 园豆:200
提问于:2011-11-03 18:23
< >
分享
最佳答案
0

换一个支持的包,或修改现有的这个包

参考http://rq2-79.iteye.com/blog/128078 http://coolyongzi.iteye.com/blog/182447

2012 | 高人七级 |园豆:21228 | 2011-11-04 13:09

大侠。。。我看了一下那两个包是关于解压zip的。。。我现在是解压rar的时候出的问题。。。帮个忙。。。

pm8:鉡 | 园豆:200 (初学一级) | 2011-11-25 11:46
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册