[問題] Java IO問題

看板java作者 (卡卡小蛋)時間18年前 (2007/12/28 16:45), 編輯推噓4(403)
留言7則, 3人參與, 最新討論串1/2 (看更多)
以下是程式碼 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"); int b = 0; while ((b = gzin.read()) != -1 ) fout.write(b); gzin.close(); fout.flush(); fout.close(); } } 小弟很困惑 為什麼gzin.read()讀進來以後 沒有指定要放在什麼地方 然而 fout.write()卻知道要從什麼地方抓資料寫出 不知道有沒有哪位高手可以給一下指教 謝謝 -- 沒有人喜歡寂寞, 只是討厭失望…… 村上春樹 『挪威的森林』 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.115.84.211

12/28 16:49, , 1F
不是有嗎0.0 "test.txt"
12/28 16:49, 1F

12/28 16:50, , 2F
b = gzin.read() ... b 不就是放東西的地方嗎?
12/28 16:50, 2F

12/28 16:50, , 3F
哈... 一樓也是 super 系列 XDrz
12/28 16:50, 3F

12/28 16:51, , 4F
原來是說buffer 我誤會了Otz
12/28 16:51, 4F

12/28 16:57, , 5F
b是int吧 b應該是指read跟write的byte數 不是嗎??
12/28 16:57, 5F

12/28 17:13, , 6F
int read() Returns: the next byte of data,
12/28 17:13, 6F

12/28 17:14, , 7F
or -1 if the end of the file is reached.
12/28 17:14, 7F
文章代碼(AID): #17TBUoZp (java)
討論串 (同標題文章)
文章代碼(AID): #17TBUoZp (java)