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;
        byte[] bytes = new byte[1260];
        bStream = new BufferedInputStream(new FileInputStream(inFile));

        while ((read = bStream.read(bytes)) > 0) {
            getMarker(read);
        }
    }

 private static void getMarker(int read) {

 }

バイト配列が作成された場所と、バイト配列内のデータにアクセスできる場所がわかりません。read(おそらく long を使用して)マーカーを検索できるバイト配列になると思いましgetMarkerたが、 read は単なる整数値です。次に、バイト配列のデータはありますbytesか? または、バイト配列内の実際のバイナリ値にアクセスして検索できますか?

4

1 に答える 1

2

readメソッドは、ファイルから読み取ったデータで渡す配列の一部を埋め、読み取ったバイト数を返します。メソッドで配列にアクセスするには、getMarker読み込まれたバイト数だけでなく、そこに渡す必要があります。例えば:

    while ((read = bStream.read(bytes)) > 0) {
        getMarker(read, bytes);
    }
...

 private static void getMarker(int read, byte[] bytes) {
     // data has been read into the "bytes" array into index 0 through read-1
 }
于 2013-05-31T17:38:41.510 に答える