JavaコードでZBarバーコードリーダーのzbarimg.exeを使用したいのですが、プログラムをコンパイルすると、ウィンドウがポップアップして数秒で消えます。

user3070796
public static void main(String[] args) {
    String filePath = "C:/Program Files/ZBar/bin/zbarimg -d  C:/Program Files/ZBar/examples/barcode.png";
    try {
        System.out.println("hello");
        Process p = Runtime.getRuntime().exec(filePath);
        //BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
        System.out.println("World"); 
        final InputStream stdout = p.getInputStream();
        final OutputStream stdin = p.getOutputStream();
         new Thread(new Runnable() {
            @Override
    public void run() {
        String line;
        BufferedReader br = new BufferedReader(new InputStreamReader(stdout));
        try {
            while ((line = br.readLine()) != null) {
                System.out.println("[OUT] " + line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}).start();
          new Thread(new Runnable() {
    public void run() {
        try {
            byte[] buffer = new byte[1024];

            int bytesRead;
            while ((bytesRead = System.in.read(buffer)) != -1) {
                for(int i = 0; i < buffer.length; i++) {
                    int intValue = new Byte(buffer[i]).intValue();
                    if (intValue == 0) {
                        bytesRead = i;
                        break;
                    }
                }
                // for some reason there are 2 extra bytes on the end
                stdin.write(buffer, 0, bytesRead-2);
                System.out.println("[IN] " + new String(buffer, 0, bytesRead-2) + " [/IN]");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}).start();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

}

エリオットフレッシュ

そのようにデコードするために外部プロセスを呼び出すべきではないでしょう。外部プロセスから「\ r \ n」(別名Carraige Return Line Feed)を受け取っているのではないかと思います。私は...あなたは、デコードを実行するためのJavaライブラリを使用することをお勧めここにあるどのようにあなたがかもしれないとZXing「ゼブラクロッシング」。

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

Related 関連記事

ホットタグ

アーカイブ