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();
}
}
}