Java Scanner Read loadConf()

Here you can find the source of loadConf()

Description

load Conf

License

Open Source License

Declaration

@SuppressWarnings("resource")
    private static void loadConf() throws Exception 

Method Source Code

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

import java.io.File;

import java.util.HashMap;
import java.util.Scanner;

public class Main {
    private static final String confPath = "conf/weibo.conf";
    private static HashMap<String, String> conf = null;

    @SuppressWarnings("resource")
    private static void loadConf() throws Exception {
        if (conf == null)
            conf = new HashMap<String, String>();
        File file = new File(confPath);
        Scanner reader = new Scanner(file);
        while (reader.hasNextLine()) {
            String line = reader.nextLine().trim();
            if (line.length() == 0)
                continue;
            if (line.startsWith("#"))
                continue;
            if (!line.contains(":"))
                throw new Exception("Invalid configuration: " + line);
            int pos = line.indexOf(':');
            String key = line.substring(0, pos).trim();
            String value = line.substring(pos + 1).trim();
            conf.put(key, value);/* w w  w .java  2s .  c o m*/
        }
        return;
    }
}

Related

  1. load(File in)
  2. load(final String fileName)
  3. load(InputStream in, int elementCountOverride)
  4. loadAWSCredentails(String file_path)
  5. loadBooleanArray(BufferedReader in)
  6. loadDoubleArray(Scanner reader)
  7. loadDoubleMatrix(Scanner reader)
  8. loadIntArray(Scanner reader)
  9. loadNDimDoubleMatrix(Scanner reader, int numberOfDim, Object nmatrix)