Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4036064
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:10:37+00:00 2026-05-20T12:10:37+00:00

I am faced with a problem i faced a few days ago. i have

  • 0

I am faced with a problem i faced a few days ago. i have to parse this file and convert the string into date. I had done the same to another CSV file few days ago. However, the new file is giving this error: java.text.ParseException: Unparseable date: “”3/4/2011″”

Why is the string getting printed with two “” around it? I think that is the root cause of the problem. I am posting the code below . Please note that the same code works for another file where the date is printed as 3/4/2011 with no “” around it.

     WritableWorkbook wbwrite=null;
     WritableSheet sheet=null;
     Label lwrite=null;
     BufferedReader br=null;
     Number n=null;

     String strFile="quotes.csv";
 String strLine = "";
     String st[];
     String delimiter="[,]";

int lineNumber = 0, tokenNumber = 0;
    int length=0;
    int counter=0;
    Calendar cal = Calendar.getInstance();

    DateTime datecell=null;

     if(strFile.equals("quotes.csv"))
     {
         System.out.print("in loop if");

         try
         {
            File file=new File("quotes.xls");
            wbwrite=Workbook.createWorkbook(file);
            System.out.print("file created");
            //path=file.getCanonicalPath();
            sheet = wbwrite.createSheet("Sheet 1", 0);
            lwrite=null;
            n=null;
            Date dtest=null;
            DateFormat df=null;
            Date dadd=null;

            df=new SimpleDateFormat("dd-mm-yy");

    //create BufferedReader to read csv file
    br = new BufferedReader( new FileReader(strFile));
    strLine = "";
    //st[]=empty;
            delimiter="[,]";
    lineNumber = 0; tokenNumber = 0;
            length=0;
    //read comma separated file line by line
    while( (strLine = br.readLine()) != null)
    {
        //System.out.print("strline="+strLine);
        //break comma separated line using ","
        st=strLine.split(delimiter);
                    length=0;
        while(length<st.length)
        {
            //display csv values
            //
            System.out.println("Line # " + lineNumber +
                    ", Token # " + tokenNumber
                    + ", Token : "+ st[length]);
                           if(tokenNumber==2)
                           {
                                 System.out.print("date="+st[length]);
                                  DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy");
                                  Date date = (Date)formatter.parse(st[length]);
                                  System.out.print("date="+date);
                                  cal.setTime(date);
                                  cal.set(Calendar.HOUR_OF_DAY, 17);
                                  cal.set(Calendar.MINUTE, 30);
                                  cal.set(Calendar.SECOND, 0);
                                  cal.set(Calendar.MILLISECOND, 0);
                                  date = cal.getTime();
                                  System.out.print("date="+date);
                                  datecell=new DateTime(tokenNumber,lineNumber,date);
                                  sheet.addCell(datecell);
                                  lwrite=new Label(tokenNumber,lineNumber,st[length]);
                                  sheet.addCell(lwrite);
                         }
                     if(tokenNumber==1||tokenNumber==5||tokenNumber==6||tokenNumber==7)
                     {
                            n=new Number(tokenNumber,lineNumber,Float.parseFloat(st[length]));
                           sheet.addCell(n);
                     }
                     tokenNumber++;
                     length++;
    }
    //reset token number
            //tokenNumber = 0;
}
    wbwrite.write();
    wbwrite.close();
}
catch(Exception e)
{
        System.out.print("error="+e);
}
  }
 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T12:10:38+00:00Added an answer on May 20, 2026 at 12:10 pm

    I solved it. The string already had leading and trailing quotes which led to double quotes when parsed. that’s why “”3/4/2011″”.
    I added

          if (st[length].startsWith("\""))
         {
          st[length] = st[length].substring(1, st[length].length());
          }
         if (st[length].endsWith("\""))
      {
            st[length] = st[length].substring(0, st[length].length() - 1);
      }
    

    Plus Even the date format was dd-MM-yyyy ; which was changed to dd/MM/yyyy. Now i am getting the correct answer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is almost identical problem which I faced a few days ago . I
I am started to learn Lua few days ago and faced next problem. How
I have faced this problem quite often during the last couple of months, during
I need to convert several Java classes to C#, but I have faced few
A few days ago, this was my question, and I found the answer. Maybe
I'm often faced with the problem of storing, in memory, a few (possibly complex)
We've faced strange problem. We have log on service, that authenticates user, adds auth
Today I faced a strange problem in C#. I have an ASP.NET page where
We have recently been faced with the problem of porting our C++ framework to
I have designed a custom section handler before but I'm faced with a problem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.