Java Path File Read nio readKeyFile(String path)

Here you can find the source of readKeyFile(String path)

Description

read Key File

License

Open Source License

Declaration

public static Map<String, Integer> readKeyFile(String path) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.IOException;

import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Main {
    public static final String A_KEY = "aKey";
    public static final String K_KEY = "kKey";
    public static final String X0 = "x0";

    public static Map<String, Integer> readKeyFile(String path) throws IOException {
        Map<String, Integer> result = new HashMap<String, Integer>();
        List<String> lines = readLinesOfFile(path);
        for (int i = 0; i < lines.size(); i++) {
            String line = lines.get(i);
            if (line.startsWith(A_KEY)) {
                result.put(A_KEY, Integer.valueOf(line.split("=")[1]));
            } else if (line.startsWith(K_KEY)) {
                result.put(K_KEY, Integer.valueOf(line.split("=")[1]));
            } else if (line.startsWith(X0)) {
                result.put(X0, Integer.valueOf(line.split("=")[1]));
            }//from   w  ww. j a  va  2 s .c  o m
        }
        return result;
    }

    public static List<String> readLinesOfFile(String path) throws IOException {
        Path pathToFile = Paths.get(path);
        return Files.readAllLines(pathToFile, StandardCharsets.US_ASCII);
    }
}

Related

  1. readFromFile(String path)
  2. readFully(Path filePath)
  3. readIntsFromFile(String filePath)
  4. readJson(Class dataClass, Path path)
  5. readJsonObject(Path path, TypeReference typeReference)
  6. readLine(BufferedReader br, Path path)
  7. readLineByLine(String filePath)
  8. readLines(Path path, boolean ignoreComments)
  9. readLineS(String filePath, int line)