`

文件读写问题

    博客分类:
  • JAVA
 
阅读更多
'赵','1234'
'钱','2345''孙','3456'
'李','4567''周','56
78'
……
这是我文件里的内容,一共是五条数据:
赵 1234
钱 2345
孙 3456
李 4567
周 5678

package com.sun.io;

import java.io.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class read {

	public static void main(String[] args) throws IOException{

		File f = new File("name.txt");
		
		BufferedReader fis = new BufferedReader(new FileReader(f));
		StringBuffer sb = new StringBuffer();
		String line = null;
		while((line=fis.readLine())!=null){
			sb.append(line);
		}
		System.out.println(sb.toString());
		
		Pattern p = Pattern.compile("[\u4E00-\u9FA5]|[0-9]{4}");
		Matcher m = p.matcher(sb.toString());
		int i = 0;
		while(m.find()){
			System.out.print(m.group()+"\t");
			i++;
			if(i%2==0){
				System.out.println();
			}
		}
	}

}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics