lose()
关闭此流,但要先刷新它。
flush()
刷新该流的缓冲。
/**
* 保存文件
* @param file 文件属性
* @param filePath 新的文件路径
*/
public static void saveFile(File file,String filePath) throws IOException {
InputStream is = null;
OutputStream os = null;
try {
is = new FileInputStream(file); //根据上传文件得到输入流
os = new FileOutputStream(new File(filePath)); //指定文件输出流
byte buffer[] = new byte[4096];
int count = 0;
while ((count = is.read(buffer)) > 0) {
os.write(buffer, 0, count);
}
os.flush();
}finally{
try {
os.close();
is.close();
} catch (IOException e) {
logger.debug(e);
throw new IOException("some unknown error happened! ");
}
}
}
|