import java.io.*;
import java.util.*;
public class test {
    public static void readFile() throws IOException {
        File f = new File("C:\\Users\\15773\\Desktop\\投递\\新建文本文档.txt");
        FileReader reader =  new FileReader(f);
        BufferedReader br = new BufferedReader(reader);
        //按行读取
        String line;
        while ((line = br.readLine()) != null){
            System.out.println(line);
        }
        br.close();
    }
    public static void main(String[] args) throws IOException{
        test.readFile();
    }
}

读取文件正则

import java.io.*;
import java.util.*;
import java.util.regex.*;
public class test {
    public static void readFile() throws IOException {
        File f = new File("C:\\Users\\15773\\Desktop\\投递\\新建文本文档.txt");
        FileReader reader =  new FileReader(f);
        BufferedReader br = new BufferedReader(reader);
        //按行读取
        String line;
        String regex="\\d+";
        while ((line = br.readLine()) != null){
//            System.out.println(line);
            if (line.matches(regex)){
                System.out.println(line+":matching regex");
            }else {
                System.out.println(line+":not matching regex");
            }
        }
        br.close();
    }
    public static void main(String[] args) throws IOException{
        test.readFile();
    }
}

 

相关文章:

  • 2022-12-23
  • 2022-01-24
  • 2022-02-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-07
猜你喜欢
  • 2022-12-23
  • 2021-11-23
  • 2022-12-23
  • 2022-02-07
  • 2022-12-23
  • 2022-01-17
  • 2021-11-20
相关资源
相似解决方案