How to Create QRCode using Java (J2SE)

user1206286 picture user1206286 · Feb 13, 2012 · Viewed 11.1k times · Source

How to create QRcode image using normal j2se. Any APIs or classes are available to do this?

Answer

Som picture Som · Feb 13, 2012

To do this you need to download following jars,

  • zxing-core-1.7.jar
  • zxing-javase-1.7.jar

from http://code.google.com/p/zxing/

try the following code

ByteArrayOutputStream out = QRCode.from("Hello World").to(ImageType.PNG).stream();

try {
    FileOutputStream fout = new FileOutputStream(new File("C:\\QR_Code.JPG"));

    fout.write(out.toByteArray());

    fout.flush();
    fout.close();

} catch (FileNotFoundException e) {
    // Do Logging
} catch (IOException e) {
    // Do Logging
} 

Hope this helps