Java Execute Systed Command in Linux
Runtime r = Runtime.getRuntime();
Process p = r.exec("uname -a");
p.waitFor();
BufferedReader b = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = "";
while ((line = b.readLine()) != null) {
System.out.println(line);
}
b.close();
JAVA open a file for appending
Are you doing this for logging purposes? If so there are several libraries for this. Two of the most popular are Log4j and Logback.
If you just want something simple, this will work:
Java 7
However, if you will be writing to the same file many times, the above has to open and close the file on the disk many times, which is a slow operation. In this case, a buffered writer is better:
Notes:
|
No comments:
Post a Comment