public File savePic(File file) {
File fileDir = new File("D:\\marTemp");
InputStream inputStream = null;
OutputStream os = null;
if(!fileDir.exists()){
System.out.println("mkdir");
fileDir.mkdir();
}
try {
byte[] bs = new byte[1024 * 1024 * 5];//1k * 1024 * 5
int len;
inputStream = new FileInputStream(file);
logger.info("inputStream:"+inputStream);
os = new FileOutputStream(fileDir.getPath()+File.separator+file.getName());
logger.info("os:"+os);
while ((len = inputStream.read(bs)) != -1) {
os.write(bs, 0, len);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
logger.info("FileNotFoundException:--------"+e.getMessage());
} catch (IOException e) {
e.printStackTrace();
logger.info("IOException:--------"+e.getMessage());
}finally {
try {
os.close();
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
logger.info("FinallyIOException:--------"+e.getMessage());
}
}
File sendFile = new File(fileDir.getPath()+File.separator+file.getName());
return sendFile;
}
File存本地
猜你喜欢
转载自blog.csdn.net/qq_19006223/article/details/81746200
今日推荐
周排行