IO流的读写拷贝
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;/*** IO流的讀寫拷貝*/
public class Demo1 {public static void main(String[] args) throws IOException {//在D盤建一個文件夾,,創建A文件,寫入數據,創建B文件夾,File file = new File("D:A");//創建文件夾Aboolean mkdirs = file.mkdirs();//創建文件demo1.txt并寫入數據File demo1 = new File(file, "demo1.txt");//創建demo1.txtboolean newFile = demo1.createNewFile();//向demo1.txt寫入數據FileOutputStream out = new FileOutputStream(demo1);out.write("啦啦啦,啦啦啦,我是demo1的賣報的小行家".getBytes());out.close();//創建demo2.txt 并拷貝demo1.txt的內容File demo2 = new File(file, "demo2.txt");//從demo1 拷貝到demo2FileInputStream inputDemo1 = new FileInputStream(demo1);FileOutputStream outputDemo2 = new FileOutputStream(demo2);byte[] arr = new byte[1024];int length;while ((length = inputDemo1.read(arr)) != -1) {outputDemo2.write(arr, 0, length);}inputDemo1.close();outputDemo2.close();}
}
總結
- 上一篇: 新代数控系统参数说明书_台湾新代宏程序编
- 下一篇: bkupexec.exe进程有什么作用