상세 컨텐츠

본문 제목

FileInputStream read() 메소드 예제

Java

by kwanghyup 2020. 6. 14. 10:26

본문

public class FileInputStreamExam {

    public static void main(String[] args) throws IOException {
        String path  = FileInputStreamExam.class.getResource("test.txt").getPath(); //[1]
        System.out.println("이 파일의 경로 : " + path);

        InputStream inputStream = new FileInputStream(path);
        int readByte;

        while ((readByte = inputStream.read())!=-1) { 
            System.out.println("읽은 바이트 : "+readByte);
            System.out.println("읽은 문자 : " + (char) readByte); // 아스키코드값 형변환
        }
        inputStream.close();
    }
}

 

[1] FileInputStreamExam.java 경로를 기준으로 파일 경로 생성 

 

 

    

 

     

 

 

   

    

 

 

관련글 더보기

댓글 영역