Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: read csv file in java

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default read csv file in java

    Hi,

    How to read upto NA(Not Applicable) and Zero values in diffrent columns from csv file using string tokenizer in java program.

    Here Columns are dynamically populated.Please repaly this QUERY asap.

    File contains like this....


    Agerange name salaray range
    0_10 KRISHNA 0_1000
    10_20 KISHORE 1000_10000
    30_NA BOOK 10000_NA
    NA_NA PAPER NA
    NA_NA PEN NA_NA
    Last edited by kishore1981; November 5th, 2012 at 07:54 AM. Reason: given some example file


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: read csv file in java

    Can you post the code you are working on?

    BTW This thread moved here from Member Introductions section.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Nov 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: read csv file in java

    Hi ,

    This my business method code...


    private void readFromVarRange(InputStream is) throws IOException{


    InputStreamReader isr = new InputStreamReader(is);
    BufferedReader br = new BufferedReader(isr);


    System.out.println("============================== ====-------------"+br);



    try
    {


    String strLine = "";
    StringTokenizer st = null;
    int lineNumber = 0, tokenNumber = 0;

    //read comma separated file line by line
    while( (strLine = br.readLine()) != null)
    {
    lineNumber++;

    //break comma separated line using ","
    st = new StringTokenizer(strLine, ",");



    while(st.hasMoreTokens())
    {
    //display csv values


    tokenNumber++;



    System.out.println("Line # " + lineNumber + ", Token # " + tokenNumber + ", Token : "+ st.nextToken());



    }

    //reset token number
    tokenNumber = 0;

    }


    }
    catch(Exception e)
    {
    System.out.println("Exception while reading csv file: " + e);
    }

    From this code I am trying to get the columns data upto NA(Not Applicable) and Zero in different columns in csv file using String tokenizer in java

    Please give me answer ASAP.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: read csv file in java

    Please Edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.

    For testing you need to provide a small, complete program that compiles and executes.

    Can you explain what the current problems are with the code? Post the program's output, explain what is wrong with it and show what you want it to be.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Java I/O File code; how to read/write file
    By ryu2le in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: September 18th, 2011, 05:51 PM
  2. Trying to read a CSV file !
    By Cruz182 in forum File I/O & Other I/O Streams
    Replies: 5
    Last Post: June 2nd, 2011, 01:30 PM
  3. Printing name tags from a csv file
    By infoman in forum Java Theory & Questions
    Replies: 8
    Last Post: January 25th, 2011, 05:20 AM
  4. Averages, Highest & using a .csv file ! ? ! ?
    By thebigtimeGNAR in forum Java Theory & Questions
    Replies: 3
    Last Post: April 14th, 2010, 11:35 AM