Java IO流读写文件

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流读写文件)