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(); } } } }