Java文件解壓縮示例
新一批的考生已經開始備戰2016年JAVA認證考試。為了幫助廣大考試新手們更加順利地複習備考,小編整理了JAVA認證複習備考資料,希望能夠對大家有所幫助。
Java實現壓縮文件的解壓縮操作,缺點是壓縮文件內不能含有文件名為中文的的文件,否則會出現如下錯誤:
Exception in thread "main" gALArgumentException: MALFORMED
at ring(Unknown Source)
at LOC(Unknown Source)
at extEntry(Unknown Source)
at ()
代碼:
package ;
import ;
import InputStream;
import OutputStream;
import tStream;
import utStream;
import ntry;
import ile;
import nputStream;
public class ZipFileDemo {
@SuppressWarnings("resource")
public static void main(String args[]) throws Exception {
File file = new File("d:" + rator + "");
File outFile = null;
ZipFile zipFile = new ZipFile(file);
ZipInputStream zipInput = new ZipInputStream(new FileInputStream(file));
ZipEntry entry = null;
InputStream input = null;
OutputStream out = null;
while ((entry = extEntry()) != null) {
tln("開始解壓縮" + ame() + "文件。。。");
outFile = new File("d:" + rator + ame());
if (!arentFile()ts()) {
arentFile()r();
}
if (!ts()) {
teNewFile();
}
input = nputStream(entry);
out = new FileOutputStream(outFile);
int temp = 0;
while ((temp = ()) != -1) {
//tln(temp);
e(temp);
}
e();
e();
}
tln("Done!");
}
}
-
java網絡編程基本知識
java網絡編程的基本知識不少,下面yjbys小編為大家分享最新最全java中網絡程序基本知識,歡迎參考學習!網絡基本知識:在java中網絡程序有兩種協議:TCP和UDP,TCP通過握手協議進行可靠的連接,UDP則是不可靠連接。IP地址:用於標記一台計算機的身份證。IP地址由網絡地址(確...
-
JAVA認證基礎知識:近似算法(格雷厄姆算法)簡介
之前做了很多貪心算法,他們都能找到最優解,這也是之所以用貪心算法的原因。貪心算法較之其他,最大的優勢體現在時間複雜度低,空間複雜度也比較低。對於試用貪心算法的題型,有兩個重要特徵:貪心策略與最優子結構。貪心策略即每步採取策略的依據;最優子結構則是指問題...
-
Java考試格林模擬題
question14)whichofthefollowinglinesofcodewillcompilewithouterror1)inti=0;if(i){tln("hello");}2)booleanb=true;booleanb2=true;if(b==b2){tln("sotrue");}3)inti=1;intj=2;if(i==1||j==2)tln("ok");4)inti=1;intj=2;if(i==1&|j==2)tln("ok");questio...
-
關於struts的解決方法
Java需要我們學習相當多的'知識,下面YJBYS小編為大家整理了關於關於struts的解決方法文章,希望對你有所幫助。try{haracterEncoding(GBK);tln(字符成功轉向);}catch(UnsupportedEncodingExceptione){tStackTrace();tln(字符轉向失敗!);}問題依舊,後來才明白,應該...