【Java】Java获取运行时路径,
分享于 点击 37424 次 点评:201
【Java】Java获取运行时路径,
问题背景:
linux操作系统,以pwd命令为例,获取运行时路径
try {
Process ps = Runtime.getRuntime().exec("pwd");
InputStream in = new BufferedInputStream(ps.getInputStream());
int ptr = 0;
StringBuffer buffer = new StringBuffer();
while ((ptr = in.read()) != -1) {
buffer.append((char) ptr);
}
System.out.println("current path : " + buffer.toString());
} catch (IOException e) {
System.out.println("exec cmd exception" + e);
}
注意此处没有解决编码问题,若是将pwd换为date,则显示会乱码。
相关文章
- 暂无相关文章
用户点评