/* author by w3cschool.cc main.java */import java.io.*;public class main { public static void main(string[] args) throws exception { bufferedwriter out1 = new bufferedwriter (new filewriter("srcfile")); out1.write("string to be copied\n"); out1.close(); inputstream in = new fileinputstream (new file("srcfile")); outputstream out = new fileoutputstream (new file("destnfile")); byte[] buf = new byte[1024]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } in.close(); out.close(); bufferedreader in1 = new bufferedreader (new filereader("destnfile")); string str; while ((str = in1.readline()) != null) { system.out.println(str); } in.close(); }}
以上代码运行输出结果为:
string to be copied
以上就是java 实例 - 将文件内容复制到另一个文件的内容。