简体   繁体   English

以相反的顺序将文件转换为字节数组

[英]Convert file to byte array in reverse order

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) 最后的一部分(例如大约1000字节)

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 我只想弄清楚,读取文件的最后1000个字节

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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