當前位置:首頁 » 編程語言 » javaunrar

javaunrar

發布時間: 2022-05-21 23:12:28

1. maven的pom怎麼引入java-unrar-decryption-supported,jar

和別的依賴一樣,添加依賴,就自動下載了。。。。。至於版本,可以先搜索到有哪些版本

~
~
~

2. linux系統下java執行帶rar命令解壓帶有空格的文件

linux下的文件名引用的時候空格要加轉義 比如

test file.rar 實際引用的時候就是 test\ file.rar

至於怎麼解決 我就不再多說了哈

3. java 以流的形式解壓帶密碼的zip

可以使用 Runtime 直接調用 winRar 的命令行命令來解壓縮
注意:
1、winRar命令使用,在dos下輸入 unrar 就可以看到全部的命令說明。該命令在winRar的安裝目錄下
2、winRar命令行命令的路徑問題,也就是path。要麼加入系統變數path中,要麼在winRar的安裝目錄下執行程序
以下是程序代碼,解壓 test.rar 到當前目錄下,密碼123

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class TestRunTime {

public static void main(String[] args) {
Runtime run = Runtime.getRuntime();
try {
Process p = run.exec("unrar e test.rar -p123");//執行解壓縮命令
BufferedInputStream in = new BufferedInputStream(p.getInputStream());
BufferedReader inBr = new BufferedReader(new InputStreamReader(in));
String lineStr;

while ((lineStr = inBr.readLine()) != null)
System.out.println(lineStr);
// 檢查命令是否執行失敗。
if (p.waitFor() != 0) {
if (p.exitValue() == 1)// p.exitValue()==0表示正常結束,1:非正常結束
System.err.println("命令執行失敗!");
}

} catch (Exception e) {
e.printStackTrace();
}

}

}

4. java unrar 中crcerror的問題

請問您是要使用unrar這個軟體,通過java來調用並解壓文件是么?
您做的是windows平台的開發吧。請問具體的rar文件的文件類型是什麼呢?很有可能您是解壓了不同格式的rar文件比如是不是有可能winrar與unrar的壓縮演算法不同,從而導致unrar解壓出現錯誤呢?您可以嘗試解壓一個用unrar壓縮的內容為dll 或者 exe的文件試試

5. JAVA 在Linux下 執行命令的問題.

你的java程序沒找到 java-unrar-src.zip吧,
你指定詳細的路徑試試看。
java執行命令時候的路徑不一定是你在shell里時候的路徑。

6. java解壓RAR文件的問題

進程沖突吧?
兩個命令一起執行的應該。。兩個rar進程應該可以同事啊~

7. java上傳xls文件到伺服器後打開提示發現不可讀取的內容

頁面jsp文件
<form name="add" action="/gxtWeb/lvjcontacts/manyContacts.action" method="post"enctype="multipart/form-data" onsubmit="return checkNull();">
<s:file name="upload"></s:file>
<input type="submit" value="導入信息" >
</form>
action處理:
public class ManyContactsAction extends ActionSupport {
private File upload;
private String uploadContentType;// 要上傳的文件的類型
private String uploadFileName;// 要上傳的文件
private ContactsManager manager;
private Contacts cbean;
private Persons pbean;
private Long gid;
private String result;
public String execute() throws Exception {
// 檢查後綴名是否符合條件,同時更改上傳文件的文件名
int filesize = this.getUploadFileName().length();
String fileEx = this.getUploadFileName().substring(
this.getUploadFileName().indexOf("."), filesize);
//獲取文件名
String fileName=uploadFileName.substring(0,uploadFileName.indexOf("."));
// 獲得上傳路徑
String realPath = ServletActionContext.getServletContext().getRealPath(
"/UploadFile/");
File saveFile=null;
if (upload != null) {
// 修改文件名,使上傳後不至於重復替代
// this.uploadFileName = new Date().getTime() + fileEx;
saveFile = new File(new File(realPath), uploadFileName);
if (!saveFile.getParentFile().exists()) {
saveFile.getParentFile().mkdirs();
}

FileUtils.File(upload, saveFile);// 到這里,文件已上傳成功
// 下面進行判斷文件是否是rar文件,是就需要解壓
if (fileEx.equals(".rar")) {
System.out.println("saveFile:" + saveFile);//rar文件所在保存路徑
System.out.println("realPath:" + realPath);//解壓後保存路徑
// 定義解壓字元串,用於解壓上傳的rar文件,注意此處需要一個unrar.exe文件
String rarpath = ServletActionContext.getServletContext()
.getRealPath("/rarFile/UNRAR.exe x -t -o+ -p- \"");
String jieya = rarpath + saveFile + "\" \"" + realPath + "\"";
Process p1 = Runtime.getRuntime().exec(jieya);// 將傳輸的rar文件解壓
p1.waitFor();
p1.destroy();
FileUtils.deleteQuietly(saveFile);// 刪除rar文件
saveFile=new File(new File(realPath),fileName+".xls");
System.out.println("解壓後:"+saveFile);
ServletActionContext.getResponse().getWriter().println(
"success!!");
}
if (fileEx.equals(".xls") || fileEx.equals(".xlsx")) {
// 開始讀取文件了,獲得第一列手機號碼
Workbook persons = Workbook.getWorkbook(saveFile);// 獲得xls文件
Sheet sheet = persons.getSheet(0);// 獲得第一個工作簿
System.out.println("列數:" + sheet.getColumns());
int count = sheet.getRows();// 取得記錄數,count行
String cphone;
// 遍歷行,獲得列數據
for (int i = 0; i < count; i++) {
cphone = sheet.getCell(0, i).getContents();// 第一列的所有行
pbean = manager.getPerson(cphone);// 獲得該用戶,查詢別的信息
cbean = new Contacts();
Long contactsid = pbean.getId();
Long pid = 10002L;
cbean.setContactsid(contactsid);// 聯系人id
cbean.setPid(pid);// 用戶本身的PID
cbean.setCid("cid");// 關系的學校ID
cbean.setGid(gid);// 分組id
manager.addPerson(cbean);
this.contactsLog.writeLog("10002", "批量添加聯系人", "批量添加聯系人操作","");
System.out.println("添加成功!");
}
}
return SUCCESS;
} else {
return INPUT;
}
}
}

xml配置:
<action name="manyContacts" class="manyContactAction">
<result name="success" type="redirectAction">personInfo.action
</result>
<result name="input" type="redirectAction">showmangpersons.action
</result>
</action>
注意:在文件解壓時,需要一個unrar.exe文件,這個文件應保存在工程相應的目錄下,我就放在webapps裡面了,
按照上面的路徑即可獲得解壓文件並進行解壓。
這里配置文件沒寫任何限制,攔截器之類,都在action裡面進行判斷了,這里只做了類型判斷,沒有別的。
[java] view plain
頁面jsp文件
<form name="add" action="/gxtWeb/lvjcontacts/manyContacts.action" method="post" enctype="multipart/form-data" onsubmit="return checkNull();">
<s:file name="upload"></s:file>
<input type="submit" value="導入信息" >
</form>
action處理:
public class ManyContactsAction extends ActionSupport {
private File upload;
private String uploadContentType;// 要上傳的文件的類型
private String uploadFileName;// 要上傳的文件
private ContactsManager manager;
private Contacts cbean;
private Persons pbean;
private Long gid;
private String result;
public String execute() throws Exception {
// 檢查後綴名是否符合條件,同時更改上傳文件的文件名
int filesize = this.getUploadFileName().length();
String fileEx = this.getUploadFileName().substring(
this.getUploadFileName().indexOf("."), filesize);
//獲取文件名
String fileName=uploadFileName.substring(0,uploadFileName.indexOf("."));
// 獲得上傳路徑
String realPath = ServletActionContext.getServletContext().getRealPath(
"/UploadFile/");
File saveFile=null;
if (upload != null) {
// 修改文件名,使上傳後不至於重復替代
// this.uploadFileName = new Date().getTime() + fileEx;
saveFile = new File(new File(realPath), uploadFileName);
if (!saveFile.getParentFile().exists()) {
saveFile.getParentFile().mkdirs();
}

FileUtils.File(upload, saveFile);// 到這里,文件已上傳成功
// 下面進行判斷文件是否是rar文件,是就需要解壓
if (fileEx.equals(".rar")) {
System.out.println("saveFile:" + saveFile);//rar文件所在保存路徑
System.out.println("realPath:" + realPath);//解壓後保存路徑
// 定義解壓字元串,用於解壓上傳的rar文件,注意此處需要一個unrar.exe文件
String rarpath = ServletActionContext.getServletContext()
.getRealPath("/rarFile/UNRAR.exe x -t -o+ -p- \"");
String jieya = rarpath + saveFile + "\" \"" + realPath + "\"";
Process p1 = Runtime.getRuntime().exec(jieya);// 將傳輸的rar文件解壓
p1.waitFor();
p1.destroy();
FileUtils.deleteQuietly(saveFile);// 刪除rar文件
saveFile=new File(new File(realPath),fileName+".xls");
System.out.println("解壓後:"+saveFile);
ServletActionContext.getResponse().getWriter().println(
"success!!");
}
if (fileEx.equals(".xls") || fileEx.equals(".xlsx")) {
// 開始讀取文件了,獲得第一列手機號碼
Workbook persons = Workbook.getWorkbook(saveFile);// 獲得xls文件
Sheet sheet = persons.getSheet(0);// 獲得第一個工作簿
System.out.println("列數:" + sheet.getColumns());
int count = sheet.getRows();// 取得記錄數,count行
String cphone;
// 遍歷行,獲得列數據
for (int i = 0; i < count; i++) {
cphone = sheet.getCell(0, i).getContents();// 第一列的所有行
pbean = manager.getPerson(cphone);// 獲得該用戶,查詢別的信息
cbean = new Contacts();
Long contactsid = pbean.getId();
Long pid = 10002L;
cbean.setContactsid(contactsid);// 聯系人id
cbean.setPid(pid);// 用戶本身的PID
cbean.setCid("cid");// 關系的學校ID
cbean.setGid(gid);// 分組id
manager.addPerson(cbean);
this.contactsLog.writeLog("10002", "批量添加聯系人", "批量添加聯系人操作", "");
System.out.println("添加成功!");
}
}
return SUCCESS;
} else {
return INPUT;
}
}
}

xml配置:
<action name="manyContacts" class="manyContactAction">
<result name="success" type="redirectAction">personInfo.action
</result>
<result name="input" type="redirectAction">showmangpersons.action
</result>
</action>
注意:在文件解壓時,需要一個unrar.exe文件,這個文件應保存在工程相應的目錄下,我就放在webapps裡面了,
按照上面的路徑即可獲得解壓文件並進行解壓。
這里配置文件沒寫任何限制,攔截器之類,都在action裡面進行判斷了,這里只做了類型判斷,沒有別的。

8. java調用cmd 解壓命令

unrar命令在window環境變數里有路徑信息,所以在命令提示符里能找到並運行unrar這個命令,到JAVA程序里就沒有路徑信息,反以就找不到了,要加上unrar命令的絕對路徑才能找到。比如:如果unrar命令在c盤下就這樣寫
Runtime.getRuntime().exec("c:\\unrar x e:\1.rar e:\");

9. Java 如何實現加密rar 文件的解壓操作

這一類的開源項目並不是很多,其中有一個unrar的項目有提供加密文件的解壓

10. 在LINUX下 用JAVA如何解壓rar文件

下載地址:http://www.rarsoft.com/download.htm(目前最新為RAR 3.71 for Linux)

以最新的為准。

對於Window下的常見壓縮文件.zip和.rar,Linux也有相應的方法來解壓它們:

1:對於.zip

linux下提供了zip和unzip程序,zip是壓縮程序,unzip是解壓程序。它們的參數選項很多,這里只做簡單介紹,舉例說明一下其用法:

# zip all.zip *.jpg(這條命令是將所有.jpg的文件壓縮成一個zip包)

# unzip all.zip(這條命令是將all.zip中的所有文件解壓出來)

2:對於.rar

要在linux下處理.rar文件,需要安裝RAR for Linux,可以從網上下載,但要記住,RAR for Linux不是免費的;可從http://www.rarsoft.com/download.htm下載RAR 3。60 for Linux ,然後安裝其安裝操作如下:

# tar -xzpvf rarlinux-3.2.0.tar.gz
# cd rar
# make

這樣就安裝好了,安裝後就有了rar和unrar這兩個程序,rar是壓縮程序,unrar是解壓程序。它們的參數選項很多,舉例說明一下其用法

# rar a all *.jpg

這條命令是將所有.jpg的文件壓縮成一個rar包,名為all.rar,該程序會將.rar 擴展名將自動附加到包名後。

# unrar e all.rar

這條命令是將all.rar中的所有文件解壓出來。

linux下的文件名引用的時候空格要加轉義 比如

test file.rar 實際引用的時候就是 test\ file.rar

至於怎麼解決 我就不再多說了哈

熱點內容
網站會員注冊源碼 發布:2025-02-14 01:09:45 瀏覽:657
小火山視頻密碼是什麼 發布:2025-02-14 01:09:40 瀏覽:505
我的世界手機創的伺服器電腦能進嗎 發布:2025-02-14 01:08:16 瀏覽:163
eclipseandroid運行 發布:2025-02-14 00:54:57 瀏覽:897
雲伺服器安全策略 發布:2025-02-14 00:54:07 瀏覽:289
小米手機如何更改賬號密碼 發布:2025-02-14 00:48:48 瀏覽:572
我的世界如何導出伺服器 發布:2025-02-14 00:48:39 瀏覽:722
工業伺服器機箱怎麼樣 發布:2025-02-14 00:29:15 瀏覽:86
英朗壓縮機 發布:2025-02-14 00:29:12 瀏覽:678
java門面模式 發布:2025-02-14 00:29:09 瀏覽:917