Results 1 to 2 of 2
  1. #1
    caraldur is offline Member
    Join Date
    Feb 2015
    Posts
    27
    Rep Power
    0

    Default CVS import DateTimeParseException

    Hello again,

    I am currently trying to import a CVS file to fill an obervablelist, which will then fill a tableview. I keep getting an DateTime.Parse.Exception on the first line. I'm not sure what is causing the error, below is some of the code I am using to pull data from the CVS file.

    Java FX Code:
    //Create the file reader
    			fileReader = new BufferedReader(new FileReader(fileName));
    		
    			
    			fileReader.readLine();
    			//Read the file line by line starting from the second line
    			while ((line = fileReader.readLine()) != null) 
    			{
    				//Get all tokens available in line
    				String[] tokens = line.split(COMMA_DELIMITER);
    				
    				log.info("Ship Date: " + tokens[SHIP_DATE]);
    				
    				if (tokens.length > 0) 
    				{
    					LocalDate date = LocalDate.parse(tokens[SHIP_DATE], DateTimeFormatter.ISO_LOCAL_DATE);
    					//log.info("Formatted date: "+date);
    					
    					shippingFile.add(new ShippingData(date,tokens[PRODUCTID],tokens[INVOICE],tokens[SAP_NUMBER],tokens[DELIVERY_NUMBER],
    							tokens[SHIP_VIA],tokens[TRACKING_NUMBER], Integer.parseInt(tokens[QTY_SHIPPED])));
    				}
    			}
    Here is the exception i am getting:
    Java FX Code:
    Caused by: java.time.format.DateTimeParseException: Text '5/8/2017' could not be parsed at index 0
    	at java.time.format.DateTimeFormatter.parseResolved0(Unknown Source)
    	at java.time.format.DateTimeFormatter.parse(Unknown Source)
    	at java.time.LocalDate.parse(Unknown Source)
    	at whitman.fa.inventory.classes.CVSImport.readShippingFile(CVSImport.java:63)
    Can someone point me in the right direction so I can fix this error. Any help would be appreciated.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    25

    Default Re: CVS import DateTimeParseException

    If you look at the API for DateTimeFormatter you'll see that ISO_LOCAL_DATE has the format as 'yyyy-MM-dd'.

    You appear to be giving it 'd/M/yyyy'.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. file import which is not standard import
    By willemjav in forum New To Java
    Replies: 11
    Last Post: 04-06-2014, 06:58 AM
  2. import from xls to xml
    By abhi140291 in forum XML
    Replies: 1
    Last Post: 11-25-2013, 11:32 AM
  3. import.acm ?
    By javajosh in forum New To Java
    Replies: 4
    Last Post: 07-12-2012, 06:41 PM
  4. How do you import?
    By Gary20 in forum New To Java
    Replies: 2
    Last Post: 01-28-2011, 06:12 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
  •