2013-05-31 3 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) { 

} 

long 1234567890을 bufferedInputStream에서 찾고 싶습니다. bufferedInputStream을 긴 유형으로 검색 할 수 있습니까? (필자는 매개 변수로 '읽기'가 필요한지 잘 모르겠다. 의심 스럽지만 제거 할 수있다.) bufferedInputStream은 어떻게 검색합니까?자바, 이진 파일 입력에서 오랫동안 검색

+1

'long'은 크기가 8 바이트입니다. 파일이 8 바이트로 정렬되어 있습니까? – fge

+0

파일에서 long이 리틀 엔디안 또는 빅 엔디안으로 작성되었는지 여부에 따라 이진 표현이 다릅니다. 그래서, 무엇이 무엇입니까? – fge

답변

0

숫자가 8 바이트 정렬 및 빅 엔디안 인 경우 DataInputStream을 사용할 수 있습니다.

그렇지 않은 경우 파일을 메모리 매핑하고 ByteBuffer.order를 사용하여 리틀 엔디안으로 순서를 변경하는 것이 좋습니다. 이렇게하면 원하는 방식으로 파일에 액세스 할 수 있습니다.