Here you can find the source of getFileContentIntoStrCategoriesDictionary( String fileName)
public static HashMap<String, Integer> getFileContentIntoStrCategoriesDictionary( String fileName)
//package com.java2s; /*/*from w ww .j a va 2 s . com*/ * This file is part of the PSL software. * Copyright 2011 University of Maryland * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.HashMap; public class Main { public static HashMap<String, Integer> getFileContentIntoStrCategoriesDictionary( String fileName) { FileReader file; String line = ""; HashMap<String, Integer> dict = new HashMap<String, Integer>(); try { file = new FileReader(fileName); BufferedReader reader = new BufferedReader(file); try { while ((line = reader.readLine()) != null) { dict.put(line.split(", ")[0].trim(), Integer.valueOf(line.split(", ")[1].trim())); //returnValue += line + "\n"; } } finally { reader.close(); } } catch (FileNotFoundException e) { throw new RuntimeException("File not found"); } catch (IOException e) { throw new RuntimeException("IO Error occurred"); } return dict; } }