JavaFile筛选读取文件内容

代码如下;【思路注释在代码里】

public class LoginfoUtils {

	public static String readWantedText(String FileName, String wantedOne, String wantedTwo) {
		String Str = "";
		try {
			  //获取对应文件
			  String LogAddress = configuration.getString("log.address");
			  File f = new File(LogAddress+"//"+FileName+".log");
			  //防止读取文件内容时乱码
			  InputStreamReader read = new InputStreamReader(new FileInputStream(f),"UTF-8");
			  BufferedReader br = new BufferedReader(read);
			  //用于临时保存每次读取的内容
			  String temp = "";
			  while (temp != null) {
				  temp = br.readLine();
				  //筛选条件
				  if (temp != null && temp.contains(wantedOne) && temp.contains(wantedTwo)) {
					  Str+=temp+";";
				   }
			  }
		  
		  } catch (FileNotFoundException e) {
			  
			  e.printStackTrace();
			  
		  } catch (IOException e) {
			  
			  e.printStackTrace();
			  
		  }
		  
		  return Str;
		  
	}
	
}

你可能感兴趣的:(JavaFile,java,file)