public class Companydatabase {

    public static void main(String[] args) { 
        Companydatabase obj = new Companydatabase();
        obj.run();
    }

    public void run() {
        String File = "nishan.txt";
        BufferedReader br = null;
        String line = "";
        String split = ",";

        try {
            Map<String, String> maps = new HashMap<String, String>();

I could not add each file string to HashMap. i wish some one could help me.

            br = new BufferedReader(new FileReader(File));
            while ((line = br.readLine()) != null) { 
                // use comma as separator
                String[] country = line.split(split);
                maps.put(country[0], country[1], country[2], country[3]);
            }

            //loop map
            for (Map.Entry<String, String> entry : maps.entrySet()) {
                System.out.println("Country [code= " + entry.getKey() + " , name="
                    + entry.getValue() + "]");     
            }

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (br != null) {
                try {
                    br.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

        System.out.println("Done");
    }
}
0

There are 0 best solutions below