java文件复制代码片断(java实现文件拷贝)
发布时间:2016-12-28 来源:查字典编辑
摘要:复制代码代码如下:try{FileinputFile=newFile(args[0]);if(!inputFile.exists()){Sy...
复制代码 代码如下:
try {
File inputFile = new File(args[0]);
if (!inputFile.exists()) {
System.out.println("源文件不存在,程序终止");
System.exit(1);
}
File outputFile = new File(args[1]);
InputStream in = new FileInputStream(inputFile);
OutputStream out = new FileOutputStream(outputFile);
byte date[] = new byte[1024];
int temp = 0;
while ((temp = in.read(date)) != -1) {
out.write(date);
}
in.close();
out.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}