- while ((rec = br.readLine()) != null) {
- Pattern pCells = Pattern
- .compile("(\"[^\"]*(\"{2})*[^\"]*\")*[^,]*,");
- Matcher mCells = pCells.matcher(rec);
- System.out.println("mCells==============>"+mCells);
- List<String> cells = new ArrayList<String>();//每行记录一个list
- //读取每个单元格
- while (mCells.find()) {
- str = mCells.group();
- str = str.replaceAll(
- "(?sm)\"?([^\"]*(\"{2})*[^\"]*)\"?.*,", "$1");
- str = str.replaceAll("(?sm)(\"(\"))", "$2");
- cells.add(str);
- }
- listFile.add(cells);
- }
复制代码 我是用来读取文本中的数据的,
文本的行是这样的:
ip,status,roomid,mac,description
169.122.13.23,inactive,123,23:42:34:23:42:34,TT0
读出来的却是这样的
ip,status,roomid,mac
169.122.13.23,inactive,123,23:42:34:23:42:34
经过正则处理以后最后一列不见了 |
|