- test.txt
- 소스
import java.io.*;
import java.util.Scanner;
public class FileTestEx {
public static void main(String[] args) {
File f = new File("test.txt");
/* try{
FileReader fr = new FileReader(f);
System.out.println(fr.read());
} catch (Exception e) {
e.printStackTrace();
} */
try{
Scanner sc = new Scanner(f);
while(sc.hasNext()) // 다음 가져올 라인이 있으면 true값을 반환
System.out.println(sc.nextLine());
} catch(FileNotFoundException e){
e.printStackTrace();
}
}
}
- 결과