0260おれさま ◆6CTEZS59O00a
2018/11/04(日) 16:30:14.54public static void main(String[] args) {
FileInputStream fis = null;
FileOutputStream fos = null;
BufferedOutputStream bos = null;
GZIPOutputStream gos = null;
try {
fis = new FileInputStream("test.txt");
fos = new FileOutputStream("test.txt.gz");
bos = new BufferedOutputStream(fos);
gos = new GZIPOutputStream(bos);
int i = fis.read();
while (i != -1) {
gos.write(i);
i = fis.read();
}
} catch(IOException e) {
e.printStackTrace();
} finally {
try {
if (fis != null) fis.close();
if (gos != null) gos.close();
} catch(IOException e) {
}
}
}
}
実践編9章の練習問題
コマンドライン引数はテストが面倒なので内部指定した
test.txt を読み込んで、同じ内容を test.txt.gz にかき込むんだけど、
書込みの際のフィルタリングとして
バッファリング+圧縮
が指示されている
文字ストリームは一切使わず
バイトストリームのみで処理するため
Reader、Writer がついたクラスは出てきていないのがポイント