[Java手撕]读取指定字节的数据
public class Main {
public static void main(String[] args) throws InterruptedException, FileNotFoundException {
try(FileInputStream file = new FileInputStream("src/example.txt")) {
byte[] buffer = new byte[1024];
int bytes = -1;
while((bytes = file.read(buffer)) != -1){
System.out.println("本次读取到"+bytes+"字节");
for(int i = 0;i<bytes;i++){
System.out.println((char)buffer[i]);
}
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

浙公网安备 33010602011771号