Language/Java

[JAVA/자바/TIP2] FileReader ( cmd 창에 txt 파일 읽기/출력하기 )

reifier.tistory.com 으로 이전하였습니다. 2018. 3. 5. 20:31
반응형



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import java.io.*;
 
class RFC{    // Read File Contents ( 텍스트 파일을 읽어 cmd 에 읽는다. )
    
    FileReader fr;
    BufferedReader br;
    String fileName = "NameList.txt";
    String line;
 
    void read(){
        try{
            fr = new FileReader(fileName);
            br = new BufferedReader(fr);
            while((line = br.readLine()) != null){
                line = line.trim();
                if(line.length() != 0){
                    System.out.println("line : " + line);
                }
            }
        }catch(FileNotFoundException fnfe){
            System.out.println("[ " + fileName + " ] : Can Not Found ");
        }catch(IOException ioe){}
    }
 
    public static void main(String[] args){
        new RFC().read();
    }
}
cs









반응형