用lucene写了一个抓包程序,在检索文件过程中,我通过数据包偏移量来读取指定内容并写入新文件,但是根据偏移量单次去读可以找到文件内容,但是使用循环只能读到第一次循环的内容后面的都读取不到,我根据生成的偏移量,一次一次去查询,可以找到内容,但在这个循环里却无法找到,求大神指点
这是关键代码部分:
long start=System.currentTimeMillis();
InputStream os=new FileInputStream("dfda.cap");
DataInputStream in=new DataInputStream(os);
byte[] bytes=new byte[24];
in.read(bytes, 0, 24);
System.out.println(bytes);
FileOutputStream fos3=new FileOutputStream("abd.cap",true);
//System.out.println(bytes.length);
fos3.write(bytes);
fos3.flush();
TopDocs hits=isa.search(t1, 10);
long end=System.currentTimeMillis();
System.out.println("共花费"+(end-start)+"milliseconds");
System.out.println("共有"+hits.totalHits+"匹配");
for(ScoreDoc scoreDoc:hits.scoreDocs)
{
Document doc=isa.doc(scoreDoc.doc);
int length=Integer.parseInt(doc.get("length"));
int len=Integer.parseInt(doc.get("len"));
System.out.println(length);
System.out.println(len);
byte[] bytess=new byte[len];
in.skipBytes(length);
in.read(bytess);
System.out.println(bytess);
fos3.write(bytess);
fos3.flush();
System.out.println("写入完成!");
}
in.close();
fos3.close();
}
package mypackage;
import java.io.*;
public class Copy
{
public static void main(String[] args) throws Exception
{
String source = "E://Temp//game.swf";
String destination = "E://game.swf";
int bufferSize = 4096; // 设置缓冲区大小
byte......
答案就在这里:Java读取二进制文件
----------------------Hi,地球人,我是问答机器人小S,上面的内容就是我狂拽酷炫叼炸天的答案,除了赞同,你还有别的选择吗?