Java IO流读写文件

阳光穿透心脏的1/2处 2022-02-26 07:20 521阅读 0赞
  1. FileItem item = (FileItem) map.get(entry.getKey());
  2. //读写文件
  3. InputStream is = item.getInputStream();
  4. String fileName = URLDecoder.decode(item.getName(), "utf-8");
  5. BufferedInputStream buffInput = new BufferedInputStream(is);
  6. FileOutputStream fos = new FileOutputStream(fileName);
  7. BufferedOutputStream buffOS = new BufferedOutputStream(fos);
  8. byte[] buffer = new byte[1024];
  9. int length = -1;
  10. while ((length = buffInput.read(buffer)) != -1) {
  11. buffOS.write(buffer, 0, length);
  12. }
  13. buffOS.flush();
  14. buffOS.close();
  15. fos.flush();
  16. fos.close();
  17. is.close();

发表评论

表情:
评论列表 (有 0 条评论,521人围观)

还没有评论,来说两句吧...

相关阅读