length file from /sys/fs/cgroup/ in Java?
This question already has an answer here:
即使操作系统将文件长度报告为0
,以下方法(使用Java NIO)仍然有效:
String file = "/sys/fs/cgroup/cpu,cpuacct/cpuacct.usage";
String content = new String(Files.readAllBytes(Paths.get(file)));
System.out.println(content); // 972897369764987
I recommend the IOUtils class in the Apache Commons IO library.
As the content of those files is text, you can use the IOUtils.toString
method.
String content = IOUtils.toString(new FileInputStream(file), "UTF-8");
链接地址: http://www.djcxy.com/p/13742.html
上一篇: 从字符中构建字符串的最佳方法