title: Reading a .csv file using string.split method
body: <p>I have a .csv file which consists entry in following format:-</p>
  
  <pre><code>question,option1,option2,option3,option4,answer
  </code></pre>
  
  <p>I want to read this .csv file and insert data in a table.
  I am using string.split method for doing this and it works fine 
  for eg:-</p>
  
  <pre><code>   String a="hi,a,b,c,d,e";
      String[] b=a.split(",");
  
  output is:-
  b[0]=hi
  b[1]=a
  b[2]=b
  b[3]=c
  b[4]=d
  b[5]=e
  </code></pre>
  
  <p>but when i use space in between it gives me an error:
  for eg:-</p>
  
  <pre><code>String a="hi how are you,a,b,c,d,e";
  String[] b=a.split(",");
  </code></pre>
  
  <p>I am using this concept in a servlet which stores the values in database.
  Here is the servlet code:-</p>
  
  <pre><code> File file=new File(path2);
          Scanner inputstream=new Scanner(file);
          while(inputstream.hasNext()){
              String data=inputstream.next();
              String[] val=data.split(",");
              String sql4="insert into "+name+"(question,option1,option2,option3,option4,answer) values('"+val[0]+"','"+val[1]+"','"+val[2]+"','"+val[3]+"','"+val[4]+"','"+val[5]+"')";
              s.execute(sql4);
          }
  </code></pre>
  
  <p>I am getting Array index out of bound exception.</p>
  
  <p>Please help.</p>
  
  <p>Thankyou. :)</p>