美文网首页
2023-03-25

2023-03-25

作者: 哈迪斯Java | 来源:发表于2023-03-24 00:07 被阅读0次

    这段代码有点熟悉,但是太久没有练习了。
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.io.IOException;

    public class MyReader {

    public static void main(String[] args) {
        File me = new File("src/MyReader.java");
        BufferedReader br = null;
        FileReader fr = null;
        try {
            fr = new FileReader(me);
            br = new BufferedReader(fr);
            String tmp = null;
            while ((tmp = br.readLine()) != null) {
                System.out.println(tmp);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                br.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                fr.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    

    }

    相关文章

      网友评论

          本文标题:2023-03-25

          本文链接:https://www.haomeiwen.com/subject/mljwrdtx.html