티스토리 뷰

텍스트 파일을 읽는 샘플 프로그램


public String readFile(String filename) {

 

String string="";

 

            //reading  

            try{

                InputStream ips = new FileInputStream(filename);

                InputStreamReader ipsr = new InputStreamReader(ips,"euc-kr");

                BufferedReader br = new BufferedReader(ipsr);

                

                String line;

                while ((line=br.readLine())!=null){

                    //System.out.println(line);

                    string += line+"\n";

                }

                br.close();

            }      

            catch (Exception e){

                System.out.println(e.toString());

            }

           

            //System.out.println(string);

           

            return string;

}



댓글
댓글쓰기 폼