Java IO流读写文件

作者: 試毅_思伟 | 来源:发表于2017-12-27 10:22 被阅读270次
FileItem item = (FileItem) map.get(entry.getKey());
//读写文件
InputStream is = item.getInputStream();
String fileName = URLDecoder.decode(item.getName(), "utf-8");
BufferedInputStream buffInput = new BufferedInputStream(is);
FileOutputStream fos = new FileOutputStream(fileName);
BufferedOutputStream buffOS = new BufferedOutputStream(fos);
byte[] buffer = new byte[1024];
int length = -1;
while ((length = buffInput.read(buffer)) != -1) {
    buffOS.write(buffer, 0, length);
}
buffOS.flush();
buffOS.close();
fos.flush();
fos.close();
is.close();

相关文章

网友评论

    本文标题:Java IO流读写文件

    本文链接:https://www.haomeiwen.com/subject/jhwygxtx.html