2009-11-26 5 views
0

한 번에 x 바이트 씩 텍스트 파일을 읽고 각 "청크"를 처리하여 다른 파일에 쓰려고합니다.바이트 x에서 바이트 y까지의 Java readFile

지금까지 내가 성공적으로 할 수있는 모든은 다음과 같습니다

// read each line at a time: 
while ((str = in.readLine()) != null){ .... 

는 (400 최대 320) ... STR = in.readBytes 같은 것을 지정할 수 있습니다 ... ???

모든 의견이나 의견을 환영합니다.

답변

4

당신이 찾고있는 것은 read(byte[])입니다.

그래서 당신은 것 같은 :

InputStream in; // initialized however you're doing 
int bytesRead = 0; 
byte bytes[60]; // We'll read in up to 60 bytes at a time 
while ((bytesRead = in.read(bytes)) > 0) { 
    // bytesRead is = to the number of bytes actually read 
    // bytes array holds the next 'bytesRead' number of bytes 
}