티스토리 뷰

 

 

Beginning Java Networking

Chad Darby 외 10인 공저, 조태원 역  정보문화사 2002년, www.wrox.com


기본 입출력 클래스인 InputStream과 OutputStream을 이용한 간단한 I/O 예제

// SimpleTest.java

import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;

public class SimpleTest {

  public static void main(String args[]) {
    
    try {
      InputStream input = null;
      OutputStream output = null;

      /*
       * Here you would assign the input and output to actual streams.
       * If you had a variable s that was of type java.net.Socket, you might
       * write:
       *
       * input = s.getInputStream();
       * output = s.getOutputStream();
       */

	 byte[] b = new byte[255];
      int bytesRead = 0;

      while ((bytesRead = input.read(b)) != -1) {
        output.write(b, 0, bytesRead);
      }

      input.close();
      output.close();
    } catch (IOException io) {
      io.printStackTrace();
    }


  }
}



댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/03   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
글 보관함