您的位置:首页 > 编程语言 > Java开发

java复制单个文件 FileInputStream

2015-09-15 16:02 591 查看
public class CopydocumentTest {

public static void main(String[] args) {

String oldPath="C:\\dd\\dd.doc";
String newPath="C:\\dd\\ddcopy.doc";

try {

File oldfile = new File(oldPath);
if (oldfile.exists()) { //文件存在时

FileInputStream inStream = new FileInputStream(oldPath); //读入原文件
FileOutputStream fs = new FileOutputStream(newPath);

byte[] buffer = new byte[1024];
int length;
while ( (length = inStream.read(buffer)) != -1) {

fs.write(buffer, 0, length);
}
inStream.close();

}
}
catch (Exception e) {
System.out.println("复制单个文件操作出错");
e.printStackTrace();

}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: