package ch02;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
public class FileInputStreamTest5 {
public static void main(String[] args) {
try(FileInputStream fis = new FileInputStream ("assets/input2.txt")){
byte[] bs = new byte[10];
// fis.read(bs, 0, 5); //0부터 5까지만 읽을수있도록
// for (byte b : bs) {
// System.out.println((char)b);
// }
System.out.println("-----");
int i;
//문제1 for use index array 변경해주세요
while((i = fis.read(bs, 0, 5)) !=-1){
//길이값 넘어가지않도록 조심할 것
for (int j = 0; j <i; j++) {
System.out.print((char)bs[j]);
}
System.out.println(" : " + i + "바이트 읽음");
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
'Java > Excercise' 카테고리의 다른 글
javaio ch03 FileOutputStreamTest2 (0) | 2021.09.13 |
---|---|
javaio ch03 FileOutputStreamTest1 (0) | 2021.09.13 |
javaio ch02 FileInputStreamTest4 (0) | 2021.09.13 |
javaio ch02 FileInputStreamTest3 (0) | 2021.09.13 |
javaio ch02 FileInputStreamTest2 (0) | 2021.09.13 |