Java – converts files into byte arrays in reverse order
•
Android
byte[] bFile = new byte[(int) file.length()];
FileInputStream fileInputStream = new FileInputStream(file);
fileInputStream.read(bFile);
fileInputStream.close();
This code lets me convert the file into a byte array, and I want to read the file from beginning to end (in reverse order)
Edit: I won't read the end of the whole file (about 1000 bytes, for example)
resolvent:
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 out that I read the last 1000 bytes of the file
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码