byte[] bFile = new byte[(int) file.length()];
FileInputStream fileInputStream = new FileInputStream(file);
fileInputStream.read(bFile);
fileInputStream.close();
这段代码让我将文件转换为字节数组,我希望从头到尾读取文件(顺序相反)
编辑:我不会读取整个文件.末尾的一部分(例如约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();
我刚弄清楚,读取了文件的最后1000个字节