간단한 소스이나 메모. 

finally에서 try catch를 한번 더 해줘야 하나.. 소스도 지저분해지고 

개발서버의 경우 risk가 크지 않으므로 생략.

(실서버 또는 민감한 사항을 다루는곳에서는 추가.)


private void writeInputStreamToFile(String fileName, InputStream in) throws IOException {

        OutputStream out = null;

        try {

            out = new FileOutputStream(fileName);


            int read = 0;

            byte[] bytes = new byte[1024];


            while ((read = in.read(bytes)) != -1) {

                out.write(bytes, 0, read);

            }

        } catch (Exception e) {

            e.printStackTrace();

        } finally {

            if (out != null) {

                out.close();

            }

            if (in != null) {

                in.close();

            }

        }

        

    }

'java' 카테고리의 다른 글

TreeSet 을 사용한 List<> 중복 제거  (0) 2014.01.06
죽은 코드 저장  (0) 2013.12.12
동일성 동등성 == equals  (0) 2013.05.22
어노테이션 사용  (0) 2013.05.16
리플렉션 메소드 사용, reflection  (0) 2013.05.06

+ Recent posts