編寫一個應用程式實現檔案的複製。使用格式:java Copy 原始檔目標檔案,功能是將原始檔的內容複製到目標檔案。
阿新 • • 發佈:2019-02-19
編寫一個應用程式實現檔案的複製。使用格式:java Copy 原始檔目標檔案,功能是將原始檔的內容複製到目標檔案。
import java.io.*; public class Main{ public static void main(String args[ ]){ try{ FileReader inOne=new FileReader("a.txt"); BufferedReader inTwo= new BufferedReader(inOne); FileWriter tofile=new FileWriter("hello.txt"); BufferedWriter out= new BufferedWriter(tofile); String s=null; while((s=inTwo.readLine())!=null){ out.write(s); out.newLine(); } out.flush(); out.close(); tofile.close(); inOne=new FileReader("hello.txt"); inTwo= new BufferedReader(inOne); while((s=inTwo.readLine())!=null){ System.out.println(s); } inOne.close(); inTwo.close(); } catch(IOException e){ System.out.println(e.toString()); } } }