Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  CsvFile
Language: JAVA
Code:
import java.io.*;
import java.util.*;
public class CsvFile 
{
     @SuppressWarnings({ "resource" })
     CsvFile () throws IOException
     {
          BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
          System.out.println("Enter CSV FIle name: ");
          String csvf=br.readLine();
          BufferedReader bi=new BufferedReader(new FileReader(csvf));
          String line;
          String emp[] = null;
          LinkedHashMap<String,List<String>> m=new LinkedHashMap<String,List<String>>();
          List<String> list;
          while ((line = br.readLine()) != null) 
          {
               emp = line.split(",");     
          }
          for(int i=0;i<emp.length;i+=3)
          {
          
               list=new ArrayList<String>();
               //list=new ArrayList();
               list.add(emp[i+1]);
               list.add(emp[i+2]);
               m.put(emp[i], list);
          }
           for (Map.Entry<String, List<String>> entry : m.entrySet()) {
                 String key = entry.getKey();
                 List<String> values = entry.getValue();
                 System.out.println("Key = " + key);
                 System.out.println("Values = " + values + "\n");
             }
     }
     public static void main(String[] args) throws IOException 
     {
          @SuppressWarnings("unused")
          CsvFile csv=new CsvFile();
     }

}
Comments: