public static void main(String[] args) {
// TODO Auto-generated method stub
//copy("src/com/zsj/io/Copy01.java","copy01.txt");
copy("p.png","pcopy01.png");
}
public static void copy(String srcPath,String destPath) {
//1.創建源
//源頭
File src = new File(srcPath);
//目的地
File dest = new File(destPath);//
//2.選擇流
FileReader reader = null;
FileWriter writer = null;
try {
reader = new FileReader(src);
writer = new FileWriter(dest);
//3.操作 分段讀取
char[] flush = new char[1024];//緩沖容器
int len = -1;//接收長度
while((len = reader.read(flush)) != -1) {
writer.write(flush, 0, len);
}
//重繪
writer.flush();
}catch(FileNotFoundException e) {
e.printStackTrace();
}catch(IOException e) {
e.printStackTrace();
}finally {
try {
//alt shift z 7
//4.釋放資源 分別關閉
//先打開的后背關閉
if (null != writer) {
writer.close();
}
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
try {
if(null != reader) {
reader.close();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/118808.html
標籤:Eclipse
上一篇:關于在java版我的世界用java語言擴展一些游戲創新功能
下一篇:什么場景用到部分欄位更新?
