Archive for the ‘ Java ’ Category

java reflectioin exam

http://java.sun.com/developer/technicalArticles/ALT/Reflection/

URL 주소가 가리키는 파일 읽어서 저장

package com.test.url;

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 URLSaver {
    public static void main(String[] args) {
        if(args.length != 2) {
            System.out.println("사용법 : java URLSaver URL filename");
            System.exit(1);
        }

        URL url = null;

        try {
            url = new URL(args[0]);
        } catch (MalformedURLException e) {
            System.out.println("잘못된 URL 형식입니다.");
            System.exit(1);
            e.printStackTrace();
        }

        FileOutputStream fos = null;

        try {
            URLConnection urlConnection = url.openConnection();
            InputStream in = urlConnection.getInputStream();

            fos = new FileOutputStream(args[1]);
            byte[] buffer = new byte[512];
            int readcount = 0;

            System.out.println("읽기 시작");
            while((readcount = in.read(buffer)) != -1) {
                fos.write(buffer, 0, readcount);
            }
            System.out.println("파일 저장 완료");
        } catch (IOException e) {
             e.printStackTrace();
        } finally {
            try {
                if(fos != null) {
                    fos.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

Sun JVM의 Heap의 구조와 Garbage Collection

http://performeister.tistory.com/14