@RequestMapping( value = "/download.shtml", method = { RequestMethod.GET, RequestMethod.POST } )
public void downloadFile( HttpServletResponse response )
{
File file = new File( wjlj );
String fileName = file.getName();
response.setCharacterEncoding( "utf-8" );
response.setContentType( "multipart/form-data" );
response.setHeader( "Content-Disposition", "attachment;fileName=" + fileName );
InputStream inputStream = null;
try {
inputStream = new FileInputStream( file );
OutputStream os = response.getOutputStream();
byte[] b = new byte[2048];
int length;
while ( (length = inputStream.read( b ) ) > 0 )
{
os.write( b, 0, length );
}
os.close();
} catch ( Exception e ) {
e.printStackTrace();
} finally {
if ( inputStream != null )
{
try {
inputStream.close();
} catch ( IOException e ) {
e.printStackTrace();
}
}
}
}
document dowload
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=324533876&siteId=291194637
Ranking