導航:首頁 > 編程語言 > java破解壓縮

java破解壓縮

發布時間:2021-12-05 04:43:53

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();
}

}

}

❷ java壓縮文件怎麼解壓

後綴名為.jar的文件不要解壓,直接在java中運行就好了

❸ 能用java代碼窮舉rar密碼嗎來破解它

可以的 ,窮舉需要很久。。。暴力破解比較好。

❹ 如何破解損壞的java壓縮包

java 壓縮包?
是 .jar ? 如果損壞了那沒法弄,太麻煩了
如果沒損壞,直接解壓就可以

❺ java 解壓6萬個ZIP文件,如何提升速度

多線程,弄10個線程一起解壓試試

❻ Java 字元串壓縮與解壓

public class Demo {
public static void main(String[] args) {
change();
change2();
}

private static void change() {
String str = "AAAbbbcc111NNNnn";
StringBuffer result = new StringBuffer();

char oldChar = 'z';
int count = 1;
for (int i = 0; i < str.length(); i++) {
if (i == 0) {
oldChar = str.charAt(i);
} else if (i == (str.length() - 1)) {
++count;
result.append(oldChar + "" + count);
} else if (str.charAt(i) == oldChar) {
++count;
} else {
result.append(oldChar + "" + count);
count = 1;
oldChar = str.charAt(i);
}
}
System.out.println(str + " 轉成了 " + result);
}

private static void change2() {
String str = "A3b3c213N3n2";
StringBuffer result = new StringBuffer();

char oldChar = 'z';
try {
for (int i = 0; i < str.length(); i++) {
if (i % 2 == 0) {
oldChar = str.charAt(i);
} else {
int count = Integer.parseInt(str.substring(i, i + 1));
for (int j = 0; j < count; j++)
result.append(oldChar);
}
}
} catch (Exception e) {
System.err.println("格式異常...");
return;
}
System.out.println(str + " 轉成了 " + result);
}
}

❼ 關於Java的解壓縮的代碼


packagecom.javatest.techzero.gui;
importjava.io.File;
importjava.io.FileInputStream;
importjava.io.FileOutputStream;
importjava.io.InputStream;
importjava.io.OutputStream;
importjava.util.zip.ZipEntry;
importjava.util.zip.ZipFile;
importjava.util.zip.ZipInputStream;
publicclassZipFileDemo{
@SuppressWarnings("resource")
publicstaticvoidmain(Stringargs[])throwsException{
Filefile=newFile("d:"+File.separator+"test.zip");
FileoutFile=null;
ZipFilezipFile=newZipFile(file);
ZipInputStreamzipInput=newZipInputStream(newFileInputStream(file));
ZipEntryentry=null;
InputStreaminput=null;
OutputStreamout=null;
while((entry=zipInput.getNextEntry())!=null){
System.out.println("開始解壓縮"+entry.getName()+"文件。。。");
outFile=newFile("d:"+File.separator+entry.getName());
if(!outFile.getParentFile().exists()){
outFile.getParentFile().mkdir();
}
if(!outFile.exists()){
outFile.createNewFile();
}
input=zipFile.getInputStream(entry);
out=newFileOutputStream(outFile);
inttemp=0;
while((temp=input.read())!=-1){
<SPANstyle="WHITE-SPACE:pre"></SPAN>//System.out.println(temp);
out.write(temp);
}
input.close();
out.close();
}
System.out.println("Done!");
}
}

僅供參考

❽ java zlib 壓縮和解壓縮怎麼實現

使用java.util.zip.ZipFile 類及相關的類實現

如解壓縮內
ZipInputStream zin = new ZipInputStream(in);
ZipEntry entry = null;
while((entry=zin.getNextEntry())!容=null){
if(entry.isDirectory()||entry.getName().equals("..\\"))
continue;
BufferedInputStream bin = new BufferedInputStream(zin);
byte[] buf = new byte[];
bin.read(buf,0,1);
}

❾ 怎樣用java快速實現zip文件的壓縮解壓縮

packagezip;
importjava.io.BufferedInputStream;
importjava.io.BufferedOutputStream;
importjava.io.File;
importjava.io.FileInputStream;
importjava.io.FileOutputStream;
importjava.util.Enumeration;
importjava.util.zip.CRC32;
importjava.util.zip.CheckedOutputStream;
importjava.util.zip.ZipEntry;
importjava.util.zip.ZipFile;
importjava.util.zip.ZipOutputStream;
importorg.apache.commons.lang3.StringUtils;
publicclassZipUtil{

/**
*遞歸壓縮文件夾
*@paramsrcRootDir壓縮文件夾根目錄的子路徑
*@paramfile當前遞歸壓縮的文件或目錄對象
*@paramzos壓縮文件存儲對象
*@throwsException
*/
privatestaticvoidzip(StringsrcRootDir,Filefile,ZipOutputStreamzos)throwsException
{
if(file==null)
{
return;
}

//如果是文件,則直接壓縮該文件
if(file.isFile())
{
intcount,bufferLen=1024;
bytedata[]=newbyte[bufferLen];

//獲取文件相對於壓縮文件夾根目錄的子路徑
StringsubPath=file.getAbsolutePath();
intindex=subPath.indexOf(srcRootDir);
if(index!=-1)
{
subPath=subPath.substring(srcRootDir.length()+File.separator.length());
}
ZipEntryentry=newZipEntry(subPath);
zos.putNextEntry(entry);
BufferedInputStreambis=newBufferedInputStream(newFileInputStream(file));
while((count=bis.read(data,0,bufferLen))!=-1)
{
zos.write(data,0,count);
}
bis.close();
zos.closeEntry();
}
//如果是目錄,則壓縮整個目錄
else
{
//壓縮目錄中的文件或子目錄
File[]childFileList=file.listFiles();
for(intn=0;n<childFileList.length;n++)
{
childFileList[n].getAbsolutePath().indexOf(file.getAbsolutePath());
zip(srcRootDir,childFileList[n],zos);
}
}
}

/**
*對文件或文件目錄進行壓縮
*@paramsrcPath要壓縮的源文件路徑。如果壓縮一個文件,則為該文件的全路徑;如果壓縮一個目錄,則為該目錄的頂層目錄路徑
*@paramzipPath壓縮文件保存的路徑。注意:zipPath不能是srcPath路徑下的子文件夾
*@paramzipFileName壓縮文件名
*@throwsException
*/
publicstaticvoidzip(StringsrcPath,StringzipPath,StringzipFileName)throwsException
{
if(StringUtils.isEmpty(srcPath)||StringUtils.isEmpty(zipPath)||StringUtils.isEmpty(zipFileName))
{
thrownewParameterException(ICommonResultCode.PARAMETER_IS_NULL);
}
CheckedOutputStreamcos=null;
ZipOutputStreamzos=null;
try
{
FilesrcFile=newFile(srcPath);

//判斷壓縮文件保存的路徑是否為源文件路徑的子文件夾,如果是,則拋出異常(防止無限遞歸壓縮的發生)
if(srcFile.isDirectory()&&zipPath.indexOf(srcPath)!=-1)
{
thrownewParameterException(ICommonResultCode.INVALID_PARAMETER,".");
}

//判斷壓縮文件保存的路徑是否存在,如果不存在,則創建目錄
FilezipDir=newFile(zipPath);
if(!zipDir.exists()||!zipDir.isDirectory())
{
zipDir.mkdirs();
}

//創建壓縮文件保存的文件對象
StringzipFilePath=zipPath+File.separator+zipFileName;
FilezipFile=newFile(zipFilePath);
if(zipFile.exists())
{
//檢測文件是否允許刪除,如果不允許刪除,將會拋出SecurityException
=newSecurityManager();
securityManager.checkDelete(zipFilePath);
//刪除已存在的目標文件
zipFile.delete();
}

cos=newCheckedOutputStream(newFileOutputStream(zipFile),newCRC32());
zos=newZipOutputStream(cos);

//如果只是壓縮一個文件,則需要截取該文件的父目錄
StringsrcRootDir=srcPath;
if(srcFile.isFile())
{
intindex=srcPath.lastIndexOf(File.separator);
if(index!=-1)
{
srcRootDir=srcPath.substring(0,index);
}
}
//調用遞歸壓縮方法進行目錄或文件壓縮
zip(srcRootDir,srcFile,zos);
zos.flush();
}
catch(Exceptione)
{
throwe;
}
finally
{
try
{
if(zos!=null)
{
zos.close();
}
}
catch(Exceptione)
{
e.printStackTrace();
}
}
}

/**
*解壓縮zip包
*@paramzipFilePathzip文件的全路徑
*@paramunzipFilePath解壓後的文件保存的路徑
*@paramincludeZipFileName解壓後的文件保存的路徑是否包含壓縮文件的文件名。true-包含;false-不包含
*/
@SuppressWarnings("unchecked")
publicstaticvoinzip(StringzipFilePath,StringunzipFilePath,booleanincludeZipFileName)throwsException
{
if(StringUtils.isEmpty(zipFilePath)||StringUtils.isEmpty(unzipFilePath))
{
thrownewParameterException(ICommonResultCode.PARAMETER_IS_NULL);
}
FilezipFile=newFile(zipFilePath);
//如果解壓後的文件保存路徑包含壓縮文件的文件名,則追加該文件名到解壓路徑
if(includeZipFileName)
{
StringfileName=zipFile.getName();
if(StringUtils.isNotEmpty(fileName))
{
fileName=fileName.substring(0,fileName.lastIndexOf("."));
}
unzipFilePath=unzipFilePath+File.separator+fileName;
}
//創建解壓縮文件保存的路徑
FileunzipFileDir=newFile(unzipFilePath);
if(!unzipFileDir.exists()||!unzipFileDir.isDirectory())
{
unzipFileDir.mkdirs();
}

//開始解壓
ZipEntryentry=null;
StringentryFilePath=null,entryDirPath=null;
FileentryFile=null,entryDir=null;
intindex=0,count=0,bufferSize=1024;
byte[]buffer=newbyte[bufferSize];
BufferedInputStreambis=null;
BufferedOutputStreambos=null;
ZipFilezip=newZipFile(zipFile);
Enumeration<ZipEntry>entries=(Enumeration<ZipEntry>)zip.entries();
//循環對壓縮包里的每一個文件進行解壓
while(entries.hasMoreElements())
{
entry=entries.nextElement();
//構建壓縮包中一個文件解壓後保存的文件全路徑
entryFilePath=unzipFilePath+File.separator+entry.getName();
//構建解壓後保存的文件夾路徑
index=entryFilePath.lastIndexOf(File.separator);
if(index!=-1)
{
entryDirPath=entryFilePath.substring(0,index);
}
else
{
entryDirPath="";
}
entryDir=newFile(entryDirPath);
//如果文件夾路徑不存在,則創建文件夾
if(!entryDir.exists()||!entryDir.isDirectory())
{
entryDir.mkdirs();
}

//創建解壓文件
entryFile=newFile(entryFilePath);
if(entryFile.exists())
{
//檢測文件是否允許刪除,如果不允許刪除,將會拋出SecurityException
=newSecurityManager();
securityManager.checkDelete(entryFilePath);
//刪除已存在的目標文件
entryFile.delete();
}

//寫入文件
bos=newBufferedOutputStream(newFileOutputStream(entryFile));
bis=newBufferedInputStream(zip.getInputStream(entry));
while((count=bis.read(buffer,0,bufferSize))!=-1)
{
bos.write(buffer,0,count);
}
bos.flush();
bos.close();
}
}

publicstaticvoidmain(String[]args)
{
StringzipPath="d:\ziptest\zipPath";
Stringdir="d:\ziptest\rawfiles";
StringzipFileName="test.zip";
try
{
zip(dir,zipPath,zipFileName);
}
catch(Exceptione)
{
e.printStackTrace();
}

StringzipFilePath="D:\ziptest\zipPath\test.zip";
StringunzipFilePath="D:\ziptest\zipPath";
try
{
unzip(zipFilePath,unzipFilePath,true);
}
catch(Exceptione)
{
e.printStackTrace();
}
}
}

❿ java如何解壓一個ZIP壓縮過的數據

1樓的方法。先解壓開後,你再把文件讀成流,把數據存資料庫

閱讀全文

與java破解壓縮相關的資料

熱點內容
南昌大數據培訓 瀏覽:603
每天自動1的代碼 瀏覽:375
因為存在系統錯誤代碼193 瀏覽:56
ip網路適配器是什麼 瀏覽:61
印尼愛情電影 瀏覽:794
求一個網站帶小說的那種 瀏覽:56
pdf文件如何不能復制 瀏覽:612
都市連媽媽都收的小說 瀏覽:300
java第一步pdf 瀏覽:984
javahourofday 瀏覽:158
免費資源在線觀看2021 瀏覽:253
linuxssh命令傳文件 瀏覽:521
男漏點電影 瀏覽:46
哪裡可以充qq紅包 瀏覽:868
久久影視網 瀏覽:458
港股機構業績預測數據哪裡查 瀏覽:768
有什麼app可以督促睡覺 瀏覽:835
考研背單詞什麼app好用 瀏覽:850
usb數據線電源怎麼加 瀏覽:933
主角老婆多的都市小說 瀏覽:920

友情鏈接