作者reon (蓝冰 N I
看板java
标题Re: [问题] Java IO问题
时间Thu Jan 3 23:44:12 2008
※ 引述《CaCaEgg (卡卡小蛋)》之铭言:
: 以下是程式码
: import java.io.*;
: import java.util.zip.*;
: public class test {
: public static void main (String[] args) throws IOException {
: FileInputStream fin = new FileInputStream("test.gz");
: GZIPInputStream gzin = new GZIPInputStream(fin);
: FileOutputStream fout = new FileOutputStream("test.txt");
ByteArrayOutputStream bao = new ByteArrayOutputStream();
byte[] temp = new byte[1];
: int b = 0;
while ((b = gzin.read(temp)) != -1 ) //gzin读1byte到temp中
bao.write(temp); //将temp写到bao中
byte[] tempArray=bao.toByteArray(); // 将bao物件中资料输出
// 成byteArray
fout.write(tempArray); //写出至档案
: gzin.close();
: fout.flush();
: fout.close();
: }
: }
: 小弟很困惑
: 为什麽gzin.read()读进来以後 没有指定要放在什麽地方
: 然而
: fout.write()却知道要从什麽地方抓资料写出
: 不知道有没有哪位高手可以给一下指教
: 谢谢
我没有debug @@ 凭之前写的经验写的 有错请指教
--
最深的祝福是没有期限的
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 59.126.54.219
※ 编辑: reon 来自: 59.126.54.219 (01/03 23:44)
※ 编辑: reon 来自: 59.126.54.219 (01/03 23:45)
※ 编辑: reon 来自: 59.126.54.219 (01/03 23:46)