Java BufferedReader Read loadRealDataGraphFromEmbers(String fileName, String splitter)

Here you can find the source of loadRealDataGraphFromEmbers(String fileName, String splitter)

Description

load Real Data Graph From Embers

License

Open Source License

Declaration

public static HashMap<String, Double> loadRealDataGraphFromEmbers(String fileName, String splitter) 

Method Source Code


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

import java.io.*;

import java.util.*;

public class Main {
    public static HashMap<String, Double> loadRealDataGraphFromEmbers(String fileName, String splitter) {
        HashMap<String, Double> graph = new HashMap<String, Double>();
        BufferedReader br = null;
        try {/*from w  ww  . java  2 s  . c  o  m*/
            String sCurrentLine;
            br = new BufferedReader(new FileReader(fileName));
            while ((sCurrentLine = br.readLine()) != null) {
                String[] str = sCurrentLine.split(splitter);
                String edgeName = str[0];
                Double distance = Double.parseDouble(str[1]);
                graph.put(edgeName, distance);
            }
            if (!graph.isEmpty()) {
                System.out.println("total number of the graph edges is : " + graph.size());
            } else {
                System.out.println("there does not exist any information in the file!!");
                System.exit(0);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (br != null)
                    br.close();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
        return graph;
    }
}

Related

  1. loadPrivateKeyFile(File privateKeyFile)
  2. loadQueryFromFile(String queryFile)
  3. loadQueryNodeInfo(String input_file)
  4. loadReaderFromClasspath(Class c, String filename)
  5. loadReaderToList(Reader reader)
  6. loadSentences(InputStream stream, List jsonSentences)
  7. loadSimpleTextFile(File file, int bufferSize)
  8. loadSqlFile(String path)
  9. loadSQLFromFile(String fileName)