Java의 Java.io.FilterOutputStream 클래스

Java의 Java.io.FilterOutputStream 클래스

Java의 java.io.FilterInputStream 클래스

FilterInputStream 및 FilterOutputStream 클래스

Java.io.FilterOutputStream 클래스는 출력 스트림을 필터링하는 모든 클래스의 슈퍼클래스입니다. FilterOutputStream 클래스의 write() 메소드는 데이터를 필터링하고 이를 스트림에 따라 수행되는 기본 스트림 필터링에 씁니다.

선언 : 

public class FilterOutputStream extends OutputStream 

생성자:   

    FilterOutputStream(OutputStream 괴짜) : 출력 스트림 필터를 만듭니다.

행동 양식:  

    쓰기(int 인수) : java.io.FilterOutputStream.write(int 인수) 지정된 바이트를 출력 스트림에 씁니다. 
    구문: 
public void write(int arg)   Parameters :    arg : Source Bytes   Return :   void   Exception :    In case any I/O error occurs. 
    구현 :
Java
   // Java program illustrating the working of work(int arg)   // method   import     java.io.*  ;   import     java.lang.*  ;   public     class   NewClass   {      public     static     void     main  (  String  []     args  )     throws     IOException      {      // OutputStream FileInputStream & FilterOutputStream      // initially null      OutputStream     geek_out     =     null  ;      FilterOutputStream     geek_filter     =     null  ;      // FileInputStream used here      FileInputStream     geekinput     =     null  ;      char     c  ;      int     a  ;      try      {      // create output streams      geek_out     =     new     FileOutputStream  (  'GEEKS.txt'  );      geek_filter     =     new     FilterOutputStream  (  geek_out  );      // write(int arg) : Used to write 'M' in the file      // - 'ABC.txt'      geek_filter  .  write  (  77  );      // Flushes the Output Stream      geek_filter  .  flush  ();      // Creating Input Stream      geekinput     =     new     FileInputStream  (  'GEEKS.txt'  );      // read() method of FileInputStream :      // reading the bytes and converting next bytes to int      a     =     geekinput  .  read  ();      /* Since read() converts bytes to int so we    convert int to char for our program output*/      c     =     (  char  )  a  ;      // print character      System  .  out  .  println  (  'Character written by'     +      ' FilterOutputStream : '     +     c  );      }      catch  (  IOException     except  )      {      // if any I/O error occurs      System  .  out  .  print  (  'Write Not working properly'  );      }      finally  {      // releases any system resources associated with      // the stream      if     (  geek_out     !=     null  )      geek_out  .  close  ();      if     (  geek_filter     !=     null  )      geek_filter  .  close  ();      }      }   }   
    메모 : 
    제가 사용한 프로그램에서는 긱스.txt file 프로그램은 코드에 지정된 이름의 새 파일을 생성하고 그 안에 씁니다. 
    출력 : 
Character written by FilterOutputStream : M 
    쓰기(바이트[] 버퍼) : java.io.FilterOutputStream.write(바이트[] 버퍼) 쓴다 '인수 길이' 바이트를 출력 스트림으로 보냅니다. 
    구문: 
public void write(byte[] arg)   Parameters :    buffer : Source Buffer to be written to the Output Stream   Return :   void   Exception :    In case any I/O error occurs. 
    구현 :
Java
   // Java program illustrating the working of work(byte   // buffer) method   import     java.io.*  ;   import     java.lang.*  ;   public     class   NewClass   {      public     static     void     main  (  String  []     args  )     throws     IOException      {      // OutputStream FileInputStream & FilterOutputStream      // initially null      OutputStream     geek_out     =     null  ;      FilterOutputStream     geek_filter     =     null  ;      // FileInputStream used here      FileInputStream     geekinput     =     null  ;      byte  []     buffer     =     {  77       79       72       73       84  };      char     c  ;      int     a  ;      try      {      // create output streams      geek_out     =     new     FileOutputStream  (  'ABC.txt'  );      geek_filter     =     new     FilterOutputStream  (  geek_out  );      // writes buffer to the output stream      geek_filter  .  write  (  buffer  );      // forces byte contents to written out to the stream      geek_filter  .  flush  ();      // create input streams      geekinput     =     new     FileInputStream  (  'ABC.txt'  );      while     ((  a  =  geekinput  .  read  ())  !=-  1  )      {      // converts integer to the character      c     =     (  char  )  a  ;      // prints      System  .  out  .  print  (  c  );      }      }      catch  (  IOException     except  )      {      // if any I/O error occurs      System  .  out  .  print  (  'Write Not working properly'  );      }      finally      {      // releases any system resources associated      // with the stream      if     (  geek_out     !=     null  )      geek_out  .  close  ();      if     (  geek_filter     !=     null  )      geek_filter  .  close  ();      }      }   }   
    메모 : 
    내가 사용하는 프로그램에서 긱스.txt file 프로그램은 코드에 지정된 이름의 새 파일을 생성하고 그 안에 씁니다.

출력 :

MOHIT 
    write(byte[] buffer int offset int maxlen) : java.io.FilterOutputStream.write(byte[] buffer int offset int maxlen) 오프셋 위치에서 시작하여 지정된 버퍼의 maxlen 바이트를 출력 스트림에 씁니다.

구문: 

public void write(write(byte[] buffer int offset int maxlen)   Parameters :    buffer : Source Buffer to be written to the Output Stream   Return :   buffer : Source Buffer to be written offset : Starting offset maxlen : max no. of bytes to be written to the Output Stream   Exception :    In case any I/O error occurs. 
    플러시() : java.io.FilterOutputStream.flush() 출력 스트림을 플러시하고 스트림에 데이터를 쓸 수 없습니다. 
    구문: 
public void flush()   Parameters :    ------   Return :   void   Exception :    In case any I/O error occurs. 
    닫기() : java.io.FilterOutputStream.close() 스트림을 닫고 할당된 모든 리소스를 스트림에 해제합니다. 
    구문: 
public void close()   Parameters :    ------   Return :   void   Exception :    In case any I/O error occurs. 


설명하는 Java 프로그램: write(byte[] buffer int offset int maxlen) flash() close() 메소드

Java
   // Java program illustrating the working of   // write(byte[] buffer int offset int maxlen)   // flush() close() method   import     java.io.*  ;   import     java.lang.*  ;   public     class   NewClass   {      public     static     void     main  (  String  []     args  )     throws     IOException      {      // OutputStream FileInputStream & FilterOutputStream      // initially null      OutputStream     geek_out     =     null  ;      FilterOutputStream     geek_filter     =     null  ;      // FileInputStream used here      FileInputStream     geekinput     =     null  ;      byte  []     buffer     =     {  65       66       77       79       72       73       84  };      char     c  ;      int     a  ;      try      {      // create output streams      geek_out     =     new     FileOutputStream  (  'ABC.txt'  );      geek_filter     =     new     FilterOutputStream  (  geek_out  );      // write(byte[] buffer int offset int maxlen) :      // writes buffer to the output stream      // Here offset = 2 so it won't read first two bytes      // then maxlen = 5 so it will print max of 5 characters      geek_filter  .  write  (  buffer       2       5  );      // forces byte contents to written out to the stream      geek_filter  .  flush  ();      // create input streams      geekinput     =     new     FileInputStream  (  'ABC.txt'  );      while     ((  a     =     geekinput  .  read  ())  !=-  1  )      {      // converts integer to the character      c     =     (  char  )  a  ;      // prints      System  .  out  .  print  (  c  );      }      }      catch  (  IOException     except  )      {      // if any I/O error occurs      System  .  out  .  print  (  'Write Not working properly'  );      }      finally      {      // releases any system resources associated      // with the stream      if     (  geek_out     !=     null  )      geek_out  .  close  ();      if     (  geek_filter     !=     null  )      geek_filter  .  close  ();      }      }   }   

메모 : 
내가 사용하는 프로그램에서 긱스.txt file 프로그램은 코드에 지정된 이름의 새 파일을 생성하고 그 안에 씁니다.

출력 : 

MOHIT 


 

퀴즈 만들기