Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package utils;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.util.HashMap;
- import java.util.Iterator;
- import java.util.Map;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- System.out.println(getString("C:\\Users\\Gebruiker\\Desktop\\config.yml", "items.item"));;
- }
- public static String getString(String file, String path) {
- File f = new File(file);
- Scanner scanner = null;
- try {scanner = new Scanner(f);} catch (FileNotFoundException e) {}
- HashMap<Integer, String> map = new HashMap<>();
- HashMap<Integer, Integer> mapSpacing = new HashMap<>();
- int lineNumber = 0;
- while(scanner.hasNext()) {
- lineNumber++;
- String line = scanner.nextLine();
- map.put(lineNumber, line);
- String tmp = line.split(":")[0];
- String[] split = tmp.split(" ");
- int spaces = split.length - 1;
- mapSpacing.put(lineNumber, spaces);
- }
- int size = (path.length() - path.replace(".", "").length()) * 2;
- String name = path.substring(path.lastIndexOf(".") + 1, path.length());
- Iterator<?> it = map.entrySet().iterator();
- while (it.hasNext()) {
- @SuppressWarnings("unchecked")
- Map.Entry<Integer, String> p = (Map.Entry<Integer, String>)it.next();
- if (mapSpacing.get(p.getKey()) == size) {
- String tmp[] = p.getValue().split(":");
- String tmp1 = tmp[0].replace(" ", "");
- if (tmp1.equals(name)) {
- String split = name + ": ";
- for (int i=0; i < size; i++) {
- split = " " + split;
- }
- String tmpValue[] = p.getValue().split(split);
- if (tmpValue.length < 2) {
- return "";
- }
- String value = tmpValue[1];
- return value;
- }
- }
- }
- return "";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement