码迷,mamicode.com
首页 > 编程语言 > 详细

java检测文件内是否包含指定内容

时间:2016-09-08 21:31:48      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:

package com.test;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;


/**
 * 检测client文件是否包含指定名称
 * @author Wdnncey
 *
 */

public class Baohan {
    
    public static void main(String[] args) throws Exception {
        readF1("e:\\test.txt");        
//        readF2("e:\\test.txt");
    }
    
    public static final void readF1(String filePath) throws IOException {  
        BufferedReader br = new BufferedReader(new InputStreamReader(  
                new FileInputStream(filePath)));  
  
        for (String line = br.readLine(); line != null; line = br.readLine()) { 
            System.out.println(line);  
        }  
        br.close();  
  
    }  
  
    public static final void readF2(String filePath) throws IOException {  
        FileReader fr = new FileReader(filePath);  
        BufferedReader bufferedreader = new BufferedReader(fr);  
        String instring;  
        while ((instring = bufferedreader.readLine().trim()) != null) {  
            if (0 != instring.length()) {  
                System.out.println(instring);  
            }  
        }  
        fr.close();  
    }  

}

 

java检测文件内是否包含指定内容

标签:

原文地址:http://www.cnblogs.com/wdnnccey/p/5854406.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!