// のCSV下载の @RequestMapping(値= "/selectTaskDownFile.do"、方法= RequestMethod.GET、生産= MediaType.APPLICATION_JSON_VALUE) 公衆 ResponseEntity < バイト []> selectTaskDownFile(HttpServletRequestのREQ、HttpServletResponseのRES){ マップの<string、オブジェクト>マップ= 新しい HashMapの<> (); 文字列パス = req.getParameter(「パス」)。 試す{ // のServletContextのServletContext = req.getServletContext()。 文字列filename = path.replaceAll( "\\\\"、 "/")。スプリット( "/")[path.replaceAll( "\\\\"、 "/")。- 1 ]; // 文字列=にServletContext.getRealPathの実パス(パス); // 取得したファイルの場所 文字列のrealpath = path.replaceAll( "\\\\"、 "/"); // ファイル位置取得 にInputStreamを= 新しい新規のFileInputStream(新しい新規ファイル(実パス)); // への入力ストリーム上のファイル のバイト []本体= NULL ; 本体 = 新しい新しい バイト [in.available()]; // この入力ストリームの次の呼び出しが戻りますこの方法は、リードをブロックせずに入力ストリームを(またはスキップ)推定バイトの残り in.read(体); // 入力ストリームに読み出される fileNameに= 新しい新文字列(fileName.getBytes( "GBK")、 "ISO8859-1"); // 防止中文乱码 HttpHeadersヘッダ= 新しい HttpHeaders(); // 设置响应头 headers.add( "コンテンツ・処分"、 "添付ファイル;ファイル名=" + fileNameに)。 httpStatusからstatusCode = HttpStatus.OK。// 设置响应吗 ResponseEntity < バイト []>応答= 新しい ResponseEntity < バイト []> (本体、ヘッダーからstatusCode)。 戻り値の応答; } キャッチ(例外e){ e.printStackTrace(); ; } }