import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; public class HelloWord { public static void main(String[] args) throws IOException { String filePath = "my File.txt"; File file = new File(filePath); InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(file),"utf-8"); BufferedReader bufferedReader = new BufferedReader(inputStreamReader); List<String> lineItems=new ArrayList<String>(); String line = null; while ((line = bufferedReader.readLine()) != null) { String[] items = line.split(","); String item= items[1]; if(item.indexOf("花园")!=-1){ lineItems.add(line); } } bufferedReader.close(); inputStreamReader.close(); for(String my : lineItems){ System.out.println(my); } } }
原文:http://www.cnblogs.com/yy3b2007com/p/6708446.html