服务器存储上传的图片/文件的复制

1、先获得上传的数据(输入流)

InputStream is =fileItem.getInputStream();

2、创建输出流对接

OutputStream os=new FileOutputStream("保存的路径 ");

3、通过字节数组将数据保存在指定路径下的文件

int len=0;//记录文件位置
byte [] b=new byte[1024];//存储上传的数据
while((len=is.read(b)!=-1){
    os.write(b,0,len);
}

4、关闭流

is.close();
os.close();

猜你喜欢

转载自www.cnblogs.com/shouyaya/p/12021861.html