2010. 7. 1. 13:05
요넘 파일 가지고 놀때는 항상 API를 뒤적이더라.. 다른 넘들은 재사용을 잘하면서 요넘들은 뭐가 문제일까?

파일 전체를 문자열로 읽는 함수
/**
     * 파일 전체 읽기
     *
     * @param file
     * @return
     * @throws IOException
     */
    public static String read(File file) throws IOException {
       
        FileInputStream fis     = null;
        byte[]             buffer     = null;
       
        try {
            fis     = new FileInputStream(file);
            buffer     = new byte[fis.available()];       
            fis.read(buffer, 0, fis.available());
        } catch(IOException e) {
            throw e;
        } finally {
            if(fis != null) fis.close();
        }
       
        return new String(buffer);
    }

'java > util' 카테고리의 다른 글

[java] - replaceNull  (0) 2010.07.05
[java] - File readLine  (2) 2010.07.01
[java] - byte array to image  (0) 2010.06.30
[java] - 소수점 자르기 (duble type)  (0) 2010.06.30
[java] - base54 String decode  (0) 2010.06.30
Posted by 짱가쟁이