Skip to content

Instantly share code, notes, and snippets.

@regispires
Last active December 20, 2015 15:49
Show Gist options
  • Save regispires/6157522 to your computer and use it in GitHub Desktop.
Save regispires/6157522 to your computer and use it in GitHub Desktop.
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class CountLines {
public static void main(String[] args) {
Process p;
try {
p = Runtime.getRuntime().exec("wc -l " + args[0]);
p.waitFor();
BufferedReader b = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = b.readLine();
int lineCount = Integer.parseInt(line.split(" ")[0]);
System.out.println(lineCount);;
} catch (Exception e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment