Created
February 25, 2017 04:03
-
-
Save rlingineni/ff3a728c55e444e26211f76b2db7e072 to your computer and use it in GitHub Desktop.
Reading a Stream in Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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