0

I'm trying to get the output of a process that executes a binary file like this:

Runtime rt = Runtime.getRuntime();
String[] command = new String[]{this.binaryPath, text};
Process p = rt.exec(command);
Scanner s = new Scanner(p.getInputStream()).useDelimiter("\\A");
String output = s.hasNext() ? s.next() : "";

However when I build my project with Gradle, I get an error saying:

Task :forbiddenApisMain FAILED Forbidden method invocation: java.util.Scanner#(java.io.InputStream) [Uses default charset]

Apparently something I'm doing is forbidden by Gradle. What is it and what are my alternatives here so Gradle doesn't complain?

MTCoster
  • 5,868
  • 3
  • 28
  • 49
ninesalt
  • 4,054
  • 5
  • 35
  • 75
  • The method itself is not forbidden, but using it without an explicit charset is. Try using [`java.util.Scanner#(java.io.InputStream, java.lang.String)`](https://docs.oracle.com/javase/8/docs/api/java/util/Scanner.html#Scanner-java.io.File-java.lang.String-) instead. – MTCoster Jan 24 '19 at 17:15
  • @Mtcoster yep that works. Thank you. – ninesalt Jan 24 '19 at 17:20

0 Answers0