sitelink1  
sitelink2  
sitelink3  
sitelink4  
sitelink5  
sitelink6  

HTTPURLCONNECTION를 사용하여 웹 페이지 액세스하기 (첫번째)의 예제에서는 웹서버에서 파일을 다운로드하여 char형태로 데이터를 콘솔에 출력하고 있다.
만일 다운로드하는 파일이 바이너리 파일인 경우에는 byte형태가 아닌 char형태로 처리할 경우 데이터가 훼손되므로 유의하자.
다음의 예제는 다운로드한 데이터를 char형태가 아닌 byte형태로 처리하여 파일에 저장하고 있다.

import java.io.File;   
import java.io.FileOutputStream;   
import java.io.IOException;   
import java.io.InputStream;   
import java.net.MalformedURLException;   
import java.net.URL;   
import java.net.URLConnection;   
public class RequestTest {   
  private static URLConnection connection;   
  private static String saveFile = "D:Info.xls";   
  private static String url = "http://localhost:8080/FileDownloadTest/DownloadTest";   
  private static String uid = "down";   
  private static String pass = "test";   
  private static String compId = "103111";   
  private static void connect(String urlString) {   
    try {   
      URL url = new URL("urlString);   
      connection = url.openConnection();   
    } catch (MalformedURLException e) {   
      e.printStackTrace();   
    } catch (IOException e) {   
      e.printStackTrace();   
    }   
  }   
  private static void readContents() throws IOException {   
    FileOutputStream fileoutput = new FileOutputStream(new File(saveFile));   
    try {   
      InputStream input = connection.getInputStream();   
      byte[] buf = new byte[1024];   
      int length = 0;   
      while ((length = input.read(buf)) > 0) {   
        fileoutput.write(buf);   
      }   
      fileoutput.close();   
      input.close();   
    } catch (MalformedURLException mue) {   
      mue.printStackTrace();   
    } catch (IOException ioe) {   
      ioe.printStackTrace();   
    }   
    System.out.println("Program END!!");   
  }   
  public static void main(String[] args) throws IOException {   
    connect(url + "?id=" + uid + "&pass=" + pass + "&compId=" + compId);   
    readContents();   
  }    
}