Skip to content

Instantly share code, notes, and snippets.

@rlingineni
Created February 25, 2017 04:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rlingineni/ff3a728c55e444e26211f76b2db7e072 to your computer and use it in GitHub Desktop.
Save rlingineni/ff3a728c55e444e26211f76b2db7e072 to your computer and use it in GitHub Desktop.
Reading a Stream in Java
StringBuilder sb = new StringBuilder();
Runtime rt = Runtime.getRuntime();
//You need to use this!
String current = System.getProperty("java.class.path");
System.out.println("Current dir:"+current);
//Make sure to use -classpath flag
Process proc = rt.exec("java -classpath " + current + " Memory");
InputStream is = proc.getInputStream();
Scanner sc = new Scanner(is);
while(sc.hasNext())
{
String line = sc.nextLine();
for (int i=0; i<line.length(); i++)
{
System.out.print(line.charAt(i));
}
System.out.println();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment