String datestring = "2014101517";
New SimpleDateFormat ("YYYYMMDDHH"). Parse (datestring)
Does this code produce an error?
The answer is: No.
Here is the direct assignment to datestring a value, so parsing is not a problem.
But when the string is read from the file, be careful.
Public classParseError {/** * @paramargs*/ Public Static voidMain (string[] args) {String file= "D:/res/111.txt"; Try{String str= Myreader.readall (Newfileinputstream (file)); System.out.println (str); Date D=NewSimpleDateFormat ("YYYYMMDDHH"). Parse (str); System.out.println (d); } Catch(FileNotFoundException e) {e.printstacktrace (); } Catch(IOException e) {e.printstacktrace (); } Catch(ParseException e) {e.printstacktrace (); } }}
Like the previous piece of code, its output is this:
2014101517java.text.ParseException:Unparseable Date: "2014101517"at Java.text.DateFormat.parse ( Dateformat.java:337) at com.dhcc.jcron.ParseError.main (Parseerror.java:20)
I can't tear her sister.
In the end, it is found in debugging
This is clearly 10 characters how is Count 11?
Open Value again.
The No. 0 bit is an empty one, so the parsing goes wrong.
So what is the reason behind the problem?
Originally this file is format is UTF-8 format, UTF8 with BOM file, will put a 0xefbb in the file header.
But inputstreamreader in Java has read this BOM in.
Knowing this, I believe that the solution should be found soon, and this is not the case.
Remember the date in Java parse error