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