title: How to read csv file by using headers using java?
body: <p>I have a csv file which contains 5 header fields like field1,field2,field3,field4,field5.
  The file contains data for this headers for different users.
  Some columns may contains null values as only three columns are compulsary.</p>
  
  <p>I want to read columns by specifying its header, something like if I specified field1 and field3 then read values of these columns only.</p>
  
  <p>I tried opencsv to do that and readAll Function of opencsv.
  I also tried CSVReader.</p>
  
  <p>Here is my code : </p>
  
  <pre><code>public void startScanFile(){
  String mydemofile=pathtofile;
  BufferedReader br =null;
  try {
    System.out.println("\nEnter the column number that contains ip : ");
    br = new BufferedReader(new InputStreamReader(System.in));
    ipcolumn = Integer.parseInt(br.readLine());
        System.out.println("\nEnter the column number that contains username : ");
    br = new BufferedReader(new InputStreamReader(System.in));
    usercolumn = Integer.parseInt(br.readLine());
    System.out.println("\n Enter the column number that contains password");
    br = new BufferedReader(new InputStreamReader(System.in));
    passcolumn = Integer.parseInt(br.readLine());
      }catch(Exception e){
  }
  try {
      CSVReader csvReader = new CSVReader(new FileReader(mydemofile));
      String[] row;
      while ((row = csvReader.readNext())!=null){
      System.out.println("Col1 is is : " + row[1]);
      System.out.println("Col3 is : " + row[3]);
      System.out.println("Col4 is : " + row[4]);
  }
  } catch (FileNotFoundException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
  } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
  }
  </code></pre>
  
  <p>}</p>
  
  <p>How can I read values of specified headers only?</p>