Java File Read getFileContentIntoStrCategoriesDictionary( String fileName)

Here you can find the source of getFileContentIntoStrCategoriesDictionary( String fileName)

Description

get File Content Into Str Categories Dictionary

License

Apache License

Declaration

public static HashMap<String, Integer> getFileContentIntoStrCategoriesDictionary(
            String fileName) 

Method Source Code

//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;
    }
}

Related

  1. getFileContent(final String p_filename)
  2. getFileContentAsAString(final File aFile)
  3. getFileContentAsList(String filePath)
  4. getFileContentByLine(String filePath)
  5. getFileContentFromClasspath(String pathToFile)
  6. getFileContentLength(String filename)
  7. getFileContentList(String filenamePath)
  8. getFileContentsAsString(@Nonnull final File file)
  9. getFileContentWithoutCRNL(File f, int linesPerElement, int[] setSizes)