Class CSVParser

原文地址:http://ostermiller.org/utils/javadoc/CSVParser.html

Each line is one entry or record and the fields in a record are separated by commas。每一行是一个整体或者是一条记录,被逗号分隔开

Commas may be preceded or followed by arbitrary space and/or tab characters which are ignored.逗号前后的空格是被忽视的

Commas may be preceded or followed by arbitrary space and/or tab characters which are ignored.如果一条记录不止一行,那么所有的行都是被引号括起来

When the field is in quotes, any quote literals must be escaped by \" Backslash literals must be escaped by \\. Otherwise a backslash and the character following will be treated as the following character, IE. "\n" is equivalent to "n". Other escape sequences may be set using the setEscapes() method.里面一些特殊字符是需要被转义的

Text that comes after quotes that have been closed but come before the next comma will be ignored.在引号结束,下一个引号开始之前,中间的内容都是被忽视的。

Empty fields are returned as as String of length zero: "".

Blank lines are always ignored. Other lines will be ignored if they start with a comment character as set by the setCommentStart() method.


An example of how CSVParser might be used:

 CSVParser shredder = new CSVParser(System.in);
 shredder.setCommentStart("#;!");
 shredder.setEscapes("nrtf", "\n\r\t\f");
 String t;
 while ((t = shredder.nextValue()) != null){
     System.out.println("" + shredder.lastLineNumber() + " " + t);
 }



构造函数:

CSVParser(InputStream in)
          Create a parser to parse comma separated values from an InputStream.
CSVParser(InputStream in, char delimiter)
          Create a parser to parse delimited values from an InputStream.
CSVParser(InputStream in, char delimiter, String escapes, String replacements, String commentDelims)
          Create a parser to parse delimited values from an InputStream.
CSVParser(InputStream in, String escapes, String replacements, String commentDelims)
          Create a parser to parse comma separated values from an InputStream.
CSVParser(Reader in)
          Create a parser to parse comma separated values from a Reader.
CSVParser(Reader in, char delimiter)
          Create a parser to parse delimited values from a Reader.
CSVParser(Reader in, char delimiter, String escapes, String replacements, String commentDelims)
          Create a parser to parse delimited values from a Reader.
CSVParser(Reader in, String escapes, String replacements, String commentDelims)
          Create a parser to parse comma separated values from a Reader.


主要方法:

 voidchangeDelimiter(char newDelim)
          Change this parser so that it uses a new delimiter.
 voidchangeQuote(char newQuote)
          Change this parser so that it uses a new character for quoting.
 voidclose()
          Close any stream upon which this parser is based.
 String[][]getAllValues()
          Get all the values from the file.
 intgetLastLineNumber()
          Get the number of the line from which the last value was retrieved.
 String[]getLine()
          Get all the values from a line.
 intlastLineNumber()
          Get the line number that the last token came from.
 StringnextValue()
          get the next value.
static String[][]parse(Reader in)
          Parse the delimited data from a stream.
static String[][]parse(Reader in, char delimiter)
          Parse the comma delimited data from a stream.
static String[][]parse(Reader in, char delimiter, String escapes, String replacements, String commentDelims)
          Parse the delimited data from a stream.
static String[][]parse(Reader in, String escapes, String replacements, String commentDelims)
          Parse the comma delimited data from a stream.
static String[][]parse(String s)
          Parse the comma delimited data from a string.
static String[][]parse(String s, char delimiter)
          Parse the delimited data from a string.
static String[][]parse(String s, char delimiter, String escapes, String replacements, String commentDelims)
          Parse the delimited data from a string.
static String[][]parse(String s, String escapes, String replacements, String commentDelims)
          Parse the comma delimited data from a string.
 voidsetCommentStart(String commentDelims)
          Set the characters that indicate a comment at the beginning of the line.
 voidsetEscapes(String escapes, String replacements)
          Specify escape sequences and their replacements.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值