java字符处理流

package dadeo.filecopy;

import sun.java2d.pipe.BufferedPaints;

import java.io.*;

public class bufferinputcopy {
    public static void main(String[] args) {
        String srcpath="d:\\hello.txt";
        String destpath="d:\\hello5.txt";
        BufferedOutputStream bw=null;
        BufferedInputStream br=null;
        int  line;
        byte [] s=new byte[1024];
        try {
            bw =new BufferedOutputStream(new FileOutputStream(destpath));
            br =new BufferedInputStream(new FileInputStream(srcpath));
            while ((line=br.read(s))!=-1){
                bw.write(s,0,line);

            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if(br!=null){
                    br.close();
                }
                if(bw!=null){
                    bw.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

字符输出处理流

package dadeo.filecopy;

import java.io.*;

public class bufferreader {
    public static void main(String[] args) throws IOException {
        String filepath="d:\\hello.txt";
//            BufferedReader bufferedReader=new BufferedReader(new FileReader(filepath));
//            String line;
//            while((line=bufferedReader.readLine())!=null){
//                System.out.println(line);
//            }
//            bufferedReader.close();
        BufferedWriter bufferedWriter=new BufferedWriter(new FileWriter(filepath));
        bufferedWriter.write("hello,速战速决");
        bufferedWriter.newLine();
        bufferedWriter.write("hello,速战速决");
        bufferedWriter.newLine();
        bufferedWriter.write("hello,速战速决");
        bufferedWriter.close();
    }
}

字符读入处理流

你可能感兴趣的:(java,前端,c++)