Copy the server stores uploaded image / file

1, first obtain the uploaded data (input stream)

InputStream is =fileItem.getInputStream();

2, creating the output stream docking

OS = the OutputStream new new a FileOutputStream ( "saved path");

3, the data stored by an array of bytes in the specified file path

int len = 0; // record file location 
byte [] B = new new  byte [1024]; // store data uploaded 
the while ! ((len = is.read (B) = -. 1 ) {
    os.write(b,0,len);
}

4, close the stream

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

 

Guess you like

Origin www.cnblogs.com/shouyaya/p/12021861.html