Java开发程序猿阵线联盟-汇总各类技术干货

Java IO流读写文件

2017-12-27  本文已影响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();
上一篇下一篇

猜你喜欢

热点阅读