简体   繁体   中英

Reading .txt file in every 4 byte in java (4 byte by 4 byte!)

I tried to use below code that i found it here but my problem wasn't solved.

byte[] buffer = new byte[4];
FileInputStream fileInput = new FileInputStream("fileName.txt");
int currentByte = fileInput.read(buffer);

Your problem is that you are reading only 4 bytes. Use a while loop to keep on reading until the file is completely read.

while ((String line = fileInput.read(buffer)) != null) {
    // do something
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM