명품 JAVA 프로그래밍
명품 JAVA 프로그래밍 8장 실습문제 2
anycoding
2021. 12. 8. 17:31
반응형
문제
앞서 저장한 C:\temp\phone.txt 파일을 읽어 화면에 출력하라.
출력 예시
C:\temp\phone.txt를 출력합니다.
황기태 010-5555-7777
이재문 011-3333-4444
김남윤 065-2222-1111
소스 코드
import java.io.*;
public class Main2 {
public static void main(String[] args)
{
FileReader fin = null;
int c;
try {
fin = new FileReader("저장된 파일 위치");
System.out.println("C:\\temp\\phone.txt를 출력합니다.");
while ((c = fin.read()) != -1) {
System.out.print((char)c);
}
fin.close();;
}catch(IOException e) {
e.printStackTrace();
}
}
}
반응형