tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Tools and Libs > Ostermiller Utilities > CSV Parser

CSV Parser 

Ostermiller Java Utilities contain various components such as CSV parsing, Base64 Encoding, MD5 digest, String and Exec Helper classes. This requires the library ostermillerutils-1.08.01.jar to be in classpath. The following example shows parsing a simple CSV.

File Name  :  
com/bethecoder/tutorials/ostermillerutils/CSVParserTest.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
package com.bethecoder.tutorials.ostermillerutils;

import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;

import com.Ostermiller.util.CSVParser;
import com.Ostermiller.util.LabeledCSVParser;

public class CSVParserTest {

  /**
   @param args
   @throws IOException 
   */
  public static void main(String[] argsthrows IOException {
    
    Reader reader = new StringReader(
      "name,age,hobby\n" +
      "Sriram,2,Chess\n" +
      "Sudhakar,29,Painting"
    );
    
    LabeledCSVParser lcsvp = new LabeledCSVParser(new CSVParser(reader));

    while(lcsvp.getLine() != null){
      System.out.print("name: " + lcsvp.getValueByLabel("name"));
      System.out.print(", age: " + lcsvp.getValueByLabel("age"));
      System.out.println(", hobby: " + lcsvp.getValueByLabel("hobby"));
    }
  }

}
   

It gives the following output,
name: Sriram, age: 2, hobby: Chess
name: Sudhakar, age: 29, hobby: Painting



 
  


  
bl  br