Results 1 to 2 of 2
  1. #1
    asai is offline Senior Member
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    115
    Rep Power
    0

    Default Read data from CSV file

    Hi,

    I have this code:
    Java Code:
    String filename = textFile.getText();
            
            try {
    			
    			CsvReader cust = new CsvReader(filename);
    		
    			cust.readHeaders();
    
    			while (cust.readRecord())
    			{
    				String name   = cust.get(1);
    				String street = cust.get(2);
    				String zip    = cust.get(3);
    				String city   = cust.get(4);
    				
    				System.out.println(name + ":" + street + ":" + zip + ":" + city);
    			}
    	
    			cust.close();
    			
    		} catch (FileNotFoundException e) {
    			e.printStackTrace();
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    When I run a debugger on this, it reads the file, but it doesn't print... The string variables are empty.
    What could be missing?

  2. #2
    asai is offline Senior Member
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    115
    Rep Power
    0

    Default Re: Read data from CSV file

    Sorry... The problem was in the file...
    Replaced ; with , and the problem solved.

Similar Threads

  1. How to import(read) a data file into jtable
    By leszer in forum NetBeans
    Replies: 1
    Last Post: 06-04-2012, 06:16 AM
  2. Replies: 6
    Last Post: 06-03-2011, 11:01 AM
  3. Replies: 2
    Last Post: 03-25-2011, 03:36 PM
  4. Need a solution to read and store data from a file
    By sheetalnri in forum New To Java
    Replies: 10
    Last Post: 09-30-2010, 07:43 AM
  5. Replies: 0
    Last Post: 04-17-2008, 08:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •