赞
踩
作用:将一个输入流写入到一个文件中
- Random r = new Random();
- InputStream input = body.asInputStream();
- String fileName="D:\\demo\\"+DateUtil.format(newDate(),"yyyyMMddHHmmss")+"_"+r.nextInt(1000)+".pdf";
- File file=new File(fileName);
- if(!file.exists()){
- file.createNewFile();
- }
- BufferedInputStream in=null;
- BufferedOutputStream out=null;
- in=new BufferedInputStream(input);
- out=new BufferedOutputStream(new FileOutputStream(fileName));
- int len=-1;
- byte[] b=new byte[1024];
- while((len=in.read(b))!=-1){
- out.write(b,0,len);
- }
- in.close();
- out.close();
提示:最后一定要进行本地文件输入输出流的关闭
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。