`
kakaluyi
  • 浏览: 439533 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
社区版块
存档分类
最新评论

如何把一个文件拷贝到另一个目录

 
阅读更多
public static final boolean fileCopy( String FILE_FROM,String FILE_TO ) { 


File fileFrom = new File(FILE_FROM); 
File fileBac = new File(FILE_TO); 


boolean success = true; 
try { 
if ( !fileFrom.exists() ) { 
return false; 
} 

if ( !fileBac.exists() ) { 
success = fileBac.createNewFile(); 
} 
} catch (IOException e) { 
return false; 
} 

try { 

if (success) { 


FileInputStream input = new FileInputStream(fileFrom); 
FileOutputStream output = new FileOutputStream(fileBac); 

byte[] bytes = new byte[1024]; 
int count = 0; 
while( ( count = input.read(bytes) ) != -1 ) { 

output.write(bytes, 0, count); 
} 

input.close(); 
output.close(); 
} else { 


} 
} catch (IOException e) {return false ;} 
return true ; 

}

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics