package com.cb.action;
import java.io.*;
public class Copy {
public static void copy(InputStream is, String filePath) {
File f2 = new File(filePath); // 目标文件的File对象
if (!f2.isFile() || !f2.exists()) {
// InputStream input = null; // 准备好输入流对象,读取源文件
OutputStream out = null; // 准备好输出流对象,写入目标文件
try {
out = new FileOutputStream(f2);
int temp = 0;
try {
while ((temp = is.read()) != -1) { // 开始拷贝
out.write(temp); // 边读边写
}
System.out.println("拷贝完成!");
} catch (IOException e) {
e.printStackTrace();
System.out.println("拷贝失败!");
}
} catch (IOException e) {
e.printStackTrace();
}
}else{
System.out.println("文件已存在");
}
}
}