2009/05/12 18:06
FileReader.java - 파일의 내용을 한 줄씩 읽는다 Java SE2009/05/12 18:06
자바 IO를 이용한 FileReader 예제 소스이다. 파일이 .txt 파일이면 정상적으로 파일의 내용을 한 줄씩 읽어들여 화면에 디스플레이해 준다(사실은 표준출력한다).
import java.io.*;
public class FileReader {
public static void main (String[] args) {
System.out.println ("Program to demonstrate reading from a file");
BufferedReader br = null;
String fileName = args[0];
// If an error occurs, go to the "catch" block
try {
// FileInputStream fis = new FileInputStream (fileName);
FileReader fis = new FileReader (fileName);
br = new BufferedReader (fis);
// continue to read lines while there are still some left to read
while ( br.ready() ) {
System.out.println (br.readLine());
}
// Close the input stream
br.close();
} catch (Exception e) {
// Handle any error in opening the file
System.err.println("File input error");
}
} // End of main method
} // End of the class FileReader
'Java SE' 카테고리의 다른 글
| from String to InpuStream (0) | 2009/05/14 |
|---|---|
| FilenameFilter를 이용한 지정된 파일이름만 가져오기 (0) | 2009/05/13 |
| FileReader.java - 파일의 내용을 한 줄씩 읽는다 (0) | 2009/05/12 |
| 보안 계정으로 설정된(아이디/패스워드가 있는) SMTP 서버를 이용한 자바메일발송 (0) | 2009/05/12 |
| 이진검색 알고리즘을 재귀적 함수를 사용한 자바소스 (0) | 2009/05/12 |
| 자바 프로그램으로 윈도우 레지스트리 다루기 (0) | 2009/05/12 |
