• java--利用Filereader BufferedReader读取文本文档


    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();
        }
    }
  • 相关阅读:
    JS 面向对象
    inline-block元素间隙处理
    MUI
    MUI
    chrome://inspect调试html页面空白,DOM无法加载的解决方案
    MUI
    MUI
    MUI
    MUI
    MUI
  • 原文地址:https://www.cnblogs.com/shunguo/p/14496255.html
Copyright © 2020-2023  润新知