美文网首页
2.3.8字符流

2.3.8字符流

作者: linhaoyou | 来源:发表于2017-07-12 20:10 被阅读0次
    Paste_Image.png Paste_Image.png Paste_Image.png
    import java.io.*;
    
    public class MyReadFile {
        public static void main(String[] args){
            try {
                File f = new File("D:/work/test.txt");
                
                FileReader fr = new FileReader(f);
                
                System.out.println(fr.read());
            } catch (Exception e) {
                // TODO: handle exception
            }
        }
    }
    
    Paste_Image.png Paste_Image.png
    import java.io.*;
    
    public class MyReadFile {
        public static void main(String[] args){
            try {
                File f = new File("D:/work/test.txt");
                
                FileReader fr = new FileReader(f);
                BufferedReader br = new BufferedReader(fr);
                
                System.out.println(br.readLine());
            } catch (Exception e) {
                // TODO: handle exception
            }
        }
    }
    
    Paste_Image.png Paste_Image.png Paste_Image.png
    import java.io.*;
    
    public class MyReadFile {
        public static void main(String[] args){
            try {
                File f = new File("D:/work/test.txt");
                
                FileReader fr = new FileReader(f);
                BufferedReader br = new BufferedReader(fr);
                
                while (br.ready()) {
                    System.out.println(br.readLine());
                }           
            } catch (Exception e) {
                // TODO: handle exception
            }
        }
    }
    
    Paste_Image.png
    import java.io.*;
    
    public class MyReadFile {
        public static void main(String[] args){
            try {
                File inFile = new File("D:/work/test.txt");
                File outFile = new File("D:/test1.txt");
                
                FileReader fr = new FileReader(inFile);
                BufferedReader br = new BufferedReader(fr);
                
                FileWriter fw = new FileWriter(outFile);
                PrintWriter pw = new PrintWriter(fw);
                
                while (br.ready()) {
                    pw.println(br.readLine());
                }
                
            } catch (Exception e) {
                // TODO: handle exception
            }
        }
    }
    
    Paste_Image.png Paste_Image.png
    import java.io.*;
    
    public class MyReadFile {
        public static void main(String[] args){
            try {
                File inFile = new File("D:/work/test.txt");
                File outFile = new File("D:/test1.txt");
                
                FileReader fr = new FileReader(inFile);
                BufferedReader br = new BufferedReader(fr);
                
                FileWriter fw = new FileWriter(outFile);
                PrintWriter pw = new PrintWriter(fw);
                
                while (br.ready()) {
                    pw.println(br.readLine());
                }
                
                pw.close();
            } catch (Exception e) {
                // TODO: handle exception
            }
        }
    }
    
    Paste_Image.png Paste_Image.png

    相关文章

      网友评论

          本文标题:2.3.8字符流

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