Java代碼
/**
* //
* //
* @param oldPath the path+name of old file
* @param newPath the path+name of new file
* @throws Exception
*/
private void transferFile(String oldPath
int byteread =
File oldFile = new File(oldPath);
FileInputStream fin = null;
FileOutputStream fout = null;
try{
if(oldFile
fin = new FileInputStream(oldFile);
fout = new FileOutputStream(newPath);
byte[] buffer = new byte[
while( (byteread = fin
logger
fout
}
if(fin != null){
fin
this
}
}else{
throw new Exception(
}
}catch(Exception e){
e
throw e;
}finally{
if(fin != null){
fin
}
}
}
/**
* 刪除文件
* @param file
* @throws Exception
*/
private void delFile(File file) throws Exception {
if(!file
throw new Exception(
}
if(file
if(file
file
}else{
throw new Exception(
}
}else{
throw new Exception(
}
}
From:http://tw.wingwit.com/Article/program/Java/hx/201311/25584.html