MCPcopy Create free account
hub / github.com/oshi/oshi / getKeyValueMapFromFile

Method getKeyValueMapFromFile

oshi-core/src/main/java/oshi/util/FileUtil.java:255–268  ·  view source on GitHub ↗

Read a file and return a map of string keys to string values contained therein. Intended primarily for Linux /proc/[pid] files to provide more detailed or accurate information not available in the API. @param filename The file to read @param separator Character(s) in e

(String filename, String separator)

Source from the content-addressed store, hash-verified

253 * map is returned.
254 */
255 public static Map<String, String> getKeyValueMapFromFile(String filename, String separator) {
256 Map<String, String> map = new HashMap<>();
257 if (LOG.isDebugEnabled()) {
258 LOG.debug(READING_LOG, filename);
259 }
260 List<String> lines = FileUtil.readFile(filename, false);
261 for (String line : lines) {
262 String[] parts = line.split(separator);
263 if (parts.length == 2) {
264 map.put(parts[0], parts[1].trim());
265 }
266 }
267 return map;
268 }
269
270 /**
271 * Read a configuration file from the sequence of context classloader, system

Callers 5

testReadProcIoMethod · 0.95
getCardCodecMethod · 0.95
getCardNameMethod · 0.95
updateAttributesMethod · 0.95
updateAttributesMethod · 0.95

Calls 1

readFileMethod · 0.95

Tested by 1

testReadProcIoMethod · 0.76