Třída Java.util.zip.DeflaterOutputStream v jazyce Java
Třída Java.util.zip.DeflaterInputStream v Javě Tato třída implementuje filtr výstupního proudu pro kompresi dat v kompresním formátu 'deflate'. Používá se také jako základ pro další typy kompresních filtrů, jako je GZIPOutputStream. Konstruktéři a popis
Syntax : public void close() throws IOException Overrides: close in class FilterOutputStream Throws: IOException
Syntax : protected void deflate() throws IOException Throws: IOException
Syntax : public void finish() throws IOException Throws: IOException
Syntax : public void flush() throws IOException Overrides: flush in class FilterOutputStream Throws: IOException
Syntax : public void write(byte[] b int off int len) throws IOException Overrides: write in class FilterOutputStream Parameters: b - the data to be written off - the start offset of the data len - the length of the data Throws: IOException
Syntax : public void write(int b) throws IOException Overrides: write in class FilterOutputStream Parameters: b - the byte to be written Throws: IOExceptionJava
//Java program to demonstrate DeflaterOutputStream import java.io.FileInputStream ; import java.io.FileOutputStream ; import java.io.IOException ; import java.util.zip.DeflaterOutputStream ; class DeflaterOutputStreamDemo { public static void main ( String [] args ) throws IOException { FileOutputStream fos = new FileOutputStream ( 'file2.txt' ); //Assign FileOutputStream to DeflaterOutputStream DeflaterOutputStream dos = new DeflaterOutputStream ( fos ); //write it into DeflaterOutputStream for ( int i = 0 ; i < 10 ; i ++ ) { dos . write ( i ); } //illustrating flush() method() dos . flush (); //illustrating finish() //Finishes writing compressed data to the output stream // without closing the underlying stream dos . finish (); //fos is not closed //writing some data on file fos . write ( 'G' ); //Writes remaining compressed data to the output stream // closes the underlying stream. dos . close (); } }
Poznámka: Výstup programu nebude viditelný na online IDE, protože soubor 2.txt zde nelze přečíst. Vytvořit kvíz