java读取一个文件写入另外一个文件


package file.filereader;

import java.io.*;

/**
 *@description
 *params
 * 文件读取和写入
 */
public class FileReader {

    public static void main(String[] args) {
        File f =new File("C:\\Users\\Administrator\\Desktop\\22.sql");
        BufferedReader lineNumberReader = null;
        StringBuffer buffer = null;
        try {
            lineNumberReader= new BufferedReader(new java.io.FileReader(f));
            buffer = new StringBuffer();

            String  temp = "";
            while ((temp=lineNumberReader.readLine())!=null){
                buffer.append(temp).append("\n");
            }
            System.out.println(buffer.toString());
        }catch (IOException e){
            e.printStackTrace();
        }finally {
            try {
                lineNumberReader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        File file = null;
        file =new File("C:\\Users\\Administrator\\Desktop\\22 - 副本.sql");
        FileOutputStream fos =null;
        try {
            if (!file.exists()){
                file.createNewFile();
            }
             fos = new FileOutputStream(file);
            fos.write(buffer.toString().getBytes());
        }catch (IOException e){
            e.printStackTrace();
        }finally {
            try {
                fos.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }


    }

}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM