使用BufferReader录入文件内容并进行数据处理(字符串处理)

package demo.String;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class StringUtil {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new FileReader("F://workspace//DesignMode//src//demo//aaa.txt"));
		String str1 = "";
		String str = "";
		while ((str1 = br.readLine()) != null) {
			if (str1.contains("red")) {
				str += str1;
			}
		}
		br.close();
		System.out.println(str);
		str = str.replaceAll("\\+", "我就是爱乐乐");
		
		str = str.replaceAll("[^\\u4e00-\\u9fa5]", "");
		System.out.println(str);
		str = str.replaceAll("我就是爱乐乐", "\\|");
	//	String[] strs = str.split("我就是爱乐乐");
	//	List list = new ArrayList<>(Arrays.asList(strs));
//		System.out.println("1=====" + list.size());
//		list.removeIf(s -> s.equals(""));
//		System.out.println("2=====" + list.size());
//		System.out.println(list);
		System.out.println(str);
		
		
	}
}

 

你可能感兴趣的:(工作)