2.3.8字符流

2017-07-12  本文已影响0人  linhaoyou
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
上一篇下一篇

猜你喜欢

热点阅读