피드로 돌아가기
새로워지기·서른의 생활코딩

ex7) java.io.*

NS
normalstory
표지 이미지



//< FileInputStreamTest.java >

import java.io.*;

public class FileInputStreamTest {
public static void main( String[] args ) {
// 입력을 받이 들이는 변수 선언
int inputValue = 0;
// FileInputStream 레퍼런스 변수 선언
FileInputStream file = null;
try {
// read.txt"과 InputStream 형성
file = new FileInputStream( "C:\\java_pm\\study\\d_day01\\test\\read.txt" ); //입력전용!
//FileInputStream타입의 객체정의 -> 포인터는 file이 받는다. (read.txt로부터)
// file의 끝을 만날때 까지 데이타를 읽어 들임
while(( inputValue = file.read() ) != -1 ) { 
//-1과 같지않을때 까지 = 파일의 끝일 경우 파일 분리자 생성
System.out.print(( char )inputValue );
}
} catch ( Exception e ) {
System.out.println( e.toString() );
}
// stream을 형성한 file을 닫음
try {
file.close();
} catch ( IOException io ) {
System.out.println( io.toString() );
}
}
}
친절한 찰쓰씨
글쓴이
친절한 찰쓰씨
친절한 찰쓰씨 · 일상 UX 디자이너
기획·디자인·단상을 조용히 기록합니다.
작가 페이지에서 더 보기

이어서 읽기

새로워지기

꾸준히, 오래, 지치지 않고

Mar 31, 2026·8
새로워지기

테크 라이프 발란스

Feb 7, 2026·3
새로워지기

휴탈리티 박정렬

Feb 7, 2026·11