2013-05-31 44 views
0
Public static void main(String[] args) { 
    File inFile = null; 
    if (0 < args.length) { 
     inFile = new File(args[0]); 
    } 

    BufferedInputStream bStream = null; 

    try { 

     int read; 
     bStream = new BufferedInputStream(new FileInputStream(inFile)); 

     while ((read = bStream.read()) > 0) { 
      getMarker(read, bStream); 
      System.out.println(read); 
     } 
    } 
    catch (IOException e) { 
     e.printStackTrace(); 
    } 

    finally { 
     try { 
      if (bStream != null)bStream.close(); 
     } catch (IOException ex) { 
      ex.printStackTrace(); 
     } 
    } 
} 

private static void getMarker(int read, BufferedInputStream bStream) { 

} 

我想在bufferedInputStream中找到长1234567890。我能够搜索bufferedInputStream一个长类型? (我不确定是否需要'阅读'作为参数,我怀疑它,我可以删除它)。如何搜索bufferedInputStream?Java,在二进制文件输入中搜索一长

+1

“长”字大小为8个字节。你的文件是8字节对齐的吗? – fge

+0

更重要的是,根据你的文件中的长文件是写成小端还是大端,它的二进制表示有所不同。那么,什么是什么? – fge

回答

0

如果数字是8字节对齐且大端,则可以使用DataInputStream。

如果不是,我建议内存映射文件,并使用ByteBuffer.order更改顺序为little endian。这将允许您以任何您希望的方式访问该文件。