Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert file to byte array in reverse order

Tags:

java

android

byte[] bFile = new byte[(int) file.length()];

FileInputStream fileInputStream = new FileInputStream(file);
fileInputStream.read(bFile);
fileInputStream.close();

This code let's me convert file to byte array, am looking for reading file from end to start (in reverse order)

Edit : i dont wan't to read entire file. A part at the end (Example around 1000 bytes)

like image 826
Saiteja Prasadam Avatar asked Nov 29 '25 14:11

Saiteja Prasadam


1 Answers

File file = new File(/*file path*/);
byte[] bFile = new byte[1000];

RandomAccessFile fileInputStream = new RandomAccessFile(file, "r");
fileInputStream.seek(fileInputStream.length() - bFile[0].length);
fileInputStream.read(bFile, 0, bFile.length);
fileInputStream.close();

I just figured it out, reading last 1000 bytes of a file

like image 105
Saiteja Prasadam Avatar answered Dec 01 '25 04:12

Saiteja Prasadam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!