java 写个文件拷贝程序
1个回答
展开全部
File fileOld = new File(pathOld);
File fileNew = new File(pathNew);
if(fileOld.exists()){
try {
FileInputStream fis = new FileInputStream(fileOld);
FileOutputStream fos = new FileOutputStream(fileNew);
int read = 0;
while ((read = fis.read()) != -1) {
fos.write(read);
fos.flush();
}
fos.close();
fis.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
File fileNew = new File(pathNew);
if(fileOld.exists()){
try {
FileInputStream fis = new FileInputStream(fileOld);
FileOutputStream fos = new FileOutputStream(fileNew);
int read = 0;
while ((read = fis.read()) != -1) {
fos.write(read);
fos.flush();
}
fos.close();
fis.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询