首页 > 编程知识 正文

cr和lf是什么意思,java将csv到数据库

时间:2023-05-05 02:13:04 阅读:177188 作者:1515

iamtryingtoparseacsvfileasbelow

String NEW_LINE_SEPARATOR='rn ';

csvformatcsvfileformat=CSV format.default.withrecordseparator (new _ line _ separator );

listrecordslist=CSV parser.getrecords (;

nowthefilegotnormallinesendingwithcrlfcharactershoweverforfewlinesthereisadditionallfcharacterappearinginmiddle。

i.e。

a,b,c,dCRLF --line1

e,fLF,g,h,iCRLF --line2

Due to this,theparseoperationcreatesthreerecordswhereasactuallytheyareonlytwo。

isthereawayicangetthelfcharacterappearinginmiddleofsecondlinenottreatedaslinebreakandgettworecordsonlyuponparsing?

ithinkunivocity-parsersistheonlyparseryouwillfindthatwillworkwithlineendingsasyouexpect。

theequivalentcodeusingunivocity-parsers will be :

settings.getFormat ().setlineseparator('rn ' );

settings.getFormat ().setnormalizednewline ((u 0001 ) ); //usesaspecialcharactertorepresentanewrecordinsteadofn

settings.setnormalizelineendingswithinquotes (false; //does not replacernbythenormalizednewlinewhenreadingquotedvalues。

settings.setheaderextractionenabled (true; //extract headers from file

Settings.Trimvalues(false; //doesnotremovewhitespacesaroundvalues

csvparserparser=newcsvparser (settings;

listrecordslist=parser.parseallrecords (new file (' 201404051539.CSV ' ) );

ifyoudefinealineseparatortobernthenthisistheonlysequenceofcharactersthatshouldidentifyanewrecord (whenoutsidequotes ) nwithoutbeingenclosedinquotesbecausethat ' snotthelineseparatorsequence。

whenparsingtheinputsampleyougave :

String input='a,b,c,drne,fn,g,h,irn ';

parser.parse all (new string reader ) input );

The result will be:

LINE1=[a,b,c,d]

LINE2=[e,f]

、g、h、i]

Disclosure: I'm遗忘柜of this library.it ' sopen-sourceandfree (Apache 2.0 license ) )。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。