별초롱언니 2025. 5. 15. 17:47

Scanner클래스는 문자데이터를 읽어오는 데 도움을 주는 클래스입니다. 다양한 소스로부터 데이터를 읽어 올 수 있습니다. 

package chapter10;

import java.io.FileInputStream;
import java.util.Scanner;

public class exam76 {

	public static void main(String[] args) {
		try {
			FileInputStream fis = new FileInputStream("sample.txt");
			Scanner s = new Scanner(fis);
			
			while (s.hasNext()) {
				System.out.println(s.nextLine());
			}
		}
		catch (Exception e) {
			e.printStackTrace();
		}
	}
	
}