package jp03.part0415.study;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class BufferedReaderTest {

 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  int readCount = 0;
  try{
   BufferedReader br = new BufferedReader(new FileReader(args[0]));

   String oneLine = null;
   
   while(true){
    oneLine = br.readLine();
    if(oneLine == null){
     break;
    }
    System.out.println("한줄입력 : " + oneLine);
    readCount++;
   }
   br.close();
  } catch (FileNotFoundException e){
   e.printStackTrace();
  } catch (IOException e1){
   e1.printStackTrace();
  } finally{
   System.out.println("\n\n=====> read 횟수 readOount(줄수에 해당 ) : " + readCount);
  } 
 }
}


[원본 : test.txt]
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
//한글이 있을 경우는????
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

[결과]

사용자 삽입 이미지

'프로그램 > Java & Jsp' 카테고리의 다른 글

Java IO - (8) -> [ObjectOutputStream]  (0) 2008.08.20
Java IO - (7) -> [FileWriter]  (0) 2008.08.20
Java IO - (5) -> [FileReader]  (0) 2008.08.20
Java IO - (4) -> [FileInputStream]  (0) 2008.08.20
Java IO - (3) -> [Writer]  (0) 2008.08.20

+ Recent posts