---
title: Java
slug: brcli-java
docTags: 
createdAt: 2023-03-08T03:26:57.000Z
---

:::CodeblockTabs
```java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.File;

public class brcli_example{
	
	public static String implode(String separator, String[] data) {
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < data.length - 1; i++) {
		//data.length - 1 => to not add separator at the end
			if (!data[i].matches(" *")) {//empty string are ""; " "; "  "; and so on
				sb.append(data[i]);
				sb.append(separator);
			}
		}
		sb.append(data[data.length - 1].trim());
		return sb.toString();
	}	
	
     public static void main(String []args)  throws IOException {
		boolean isWindows = System.getProperty("os.name").toLowerCase().startsWith("windows");
		File myDir = new File(brcli_example.class.getProtectionDomain().getCodeSource().getLocation().getPath());
		
		String[] cargs = {
		(isWindows) ? ".\\BarcodeReaderCLI.exe" : "./BarcodeReaderCLI",
		"-type=code128",
		"https://wabr.inliteresearch.com/SampleImages/1d.pdf",
		"@./brcli-example.config" // Additional options and sources in configuration file
		};
				
		String cmd =  implode(" ", cargs);
        ProcessBuilder builder = new ProcessBuilder();

		if (isWindows) {
			builder.command("cmd.exe", "/c", cmd);
		} else {
			builder.command("sh", "-c", cmd);
		}
		builder.directory(myDir);
		builder.redirectErrorStream(true);
		Process process = builder.start();
		try (BufferedReader reader = new BufferedReader(
			new InputStreamReader(process.getInputStream()))) {
			String line;
			while ((line = reader.readLine()) != null) {
				System.out.println(line);
			}
		}
     }
}
```

brcli-example.config

```linux
# -silent
-type=code39
# image from URL
https://wabr.inliteresearch.com/SampleImages/1d.pdf
# image from local folder
./images/test.tif
```
:::

