zoukankan      html  css  js  c++  java
  • java检测文件内是否包含指定内容

    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();  
        }  
    
    }
  • 相关阅读:
    [POJ 1050]To the Max
    P1678 烦恼的高考志愿
    P1873 砍树
    P1102 A-B 数对
    P6771 [USACO05MAR]Space Elevator 太空电梯
    P2347 砝码称重
    P1832 A+B Problem(再升级)
    P1679 神奇的四次方数
    P1877 [HAOI2012]音量调节
    P1049 装箱问题
  • 原文地址:https://www.cnblogs.com/wdnnccey/p/5854406.html
Copyright © 2011-2022 走看看