FileInputStream read매개변수의 return값에서요....
팬지
첨으로 글올리네요 ^^
질문이 다소 정확하더라도.... 답변 부탁드려요...
자북을 보고있는데요..
1)
import java.io.*;
public class FileStreamMain4{
public static void main(String[] args) throws IOException{
FileInputStream fis = new FileInputStream(a.dat);
int i;
while( (i=fis.read()) != -1 ){
System.out.print((char)i);
}
fis.close();
} //end of main
}
결과로...예를 들어 A를 읽는다고 하면 i = 65 가 되잖아여... 이건 알겠는데....
2)
import java.io.*;
public class FileStreamMain5{
public static void main(String[] args) throws IOException{
FileInputStream fis = new FileInputStream(a.dat);
int count;
byte[] b = new byte[10];
while( (count=fis.read(b)) != -1 ){
for(int i=0; icount; i++){
System.out.print((char)b[i]);
}
}
fis.close();
} //end of main
}
여기에서 count는 어떤 값이 되나요? 예로 A를 읽는다면 count=65 가 되면 for 조건은 i65 라는 말인데... for조건을 쓴이유가 byte배열 10개를 읽는단 말인것 같은데... 해깔여요...
3)import java.io.*;
public class FileStreamMain6{
public static void main(String[] args) throws IOException{
//1. 파일 사이즈 알아내기
File f = new File(FileStreamMain6.java);
int fileSize = (int)f.length();
System.out.println(파일의 사이즈: + fileSize);
//2. 파일 사이즈에 해당하는 배열 만들기
byte[] b = new byte[fileSize];
//3. 스트림을 이용해서 배열에 데이터 채우기
FileInputStream fis = new FileInputStream(FileStreamMain6.java);
int pos = 0;
int size = 10; -첫번째 size변수 - 10byte씩 읽어라..라고 지정하는 변수.
int temp;
while( (size=fis.read(b, pos, size)) 0 ){ - 여기서size가 두번쓰였는데...모두 10을 말하는 건 아닌데 같은데....
pos += size;
temp = b.length - pos;
if(temp 10){
size = temp;
}
}
fis.close();
System.out.println(읽은 바이트수: + pos);
//4. 배열을 통째로 파일에 기록하기
FileOutputStream fos = new FileOutputStream(test.txt);
fos.write(b);
fos.close();
}
여기서 while( (size=fis.read(b, pos, size)) - While문의 첫번재 size는 값이 어떻게 되는 건가요?
궁금해요...