'Beginning'에 해당되는 글 2건

  1. 2012.09.30 [JAVA][예제] SimpleTest 예제 - Beginning Java Networking
[IT]/컴퓨터2012.09.30 00:40

 

 

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();
    }


  }
}



저작자 표시
신고
Posted by 제임스구 jamesku

티스토리 툴바