Here you can find the source of loadSystemResourceKeyValueCsvFileToMap(String resourcePath)
Parameter | Description |
---|---|
resourcePath | Path to resource file that is to be loaded into a map. |
Parameter | Description |
---|---|
IOException | an exception |
URISyntaxException | an exception |
public static Map<String, Double> loadSystemResourceKeyValueCsvFileToMap(String resourcePath) throws IOException, URISyntaxException
//package com.java2s; /*//w ww .ja v a 2s.c om * Copyright (C) 2015 higherfrequencytrading.com * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import java.nio.file.Files; import java.nio.file.Paths; import java.util.HashMap; import java.util.Map; public class Main { /** * Loads the given system resource and assumes it is a csv file with a key and value column. These key/value pairs * are loaded into a map. * * @param resourcePath Path to resource file that is to be loaded into a map. * @return Map loaded with key/value pairs from the resource file. * @throws IOException * @throws URISyntaxException */ public static Map<String, Double> loadSystemResourceKeyValueCsvFileToMap(String resourcePath) throws IOException, URISyntaxException { URL testFileUrl = ClassLoader.getSystemResource(resourcePath); URI testFileUri = testFileUrl.toURI(); Map<String, Double> results = new HashMap<>(); Files.lines(Paths.get(testFileUri)).forEach(x -> { String[] strings = x.split(","); results.put(strings[0], Double.parseDouble(strings[1])); }); return results; } }