Generate CSV and download

xiaoxiao2021-03-06  39

/ ** * 会 社 マ マ タ レコ レコ ド ド csv ファ ファ ル に に す メソ メソ ド ド. * * @Param filename ASTON made suru fu test suitable conditions name * @param in0 NADO * @return boolean * @throws Exception exception * / private boolean createCsvCompany (String filename, HttpServletRequest request, HttpServletResponse response) throws Exception {

// 戻 戻 値 Boolean RET = FALSE;

Try {

// SQL text is stringbuffer sql = new stringbuffer ();

SQL.Append ("SELECT"); sql.append ("/ n"); sql.append ("to_char (sysdate, 'yyyy / mm / dd hh: mi: ss') sdate,"); SQL.Append "Company_code,"); SQL.Append ("Company_NAME,"); SQL.Append ("Company_KANA,"); SQL.Append ("Company_SHORT_NAME,"); SQL.Append ("Company_ENGLISH,"); SQL.Append "Country,"); sql.append ("state,"); sql.append ("city,"); sql.append ("street_address1,"); sql.append ("street_address2,"); SQL.Append "CREATE_DATE,"); SQL.Append ("Update_Date"); SQL.Append ("from company"); sql.append ("/ n"); // filename = jptounicode (filename); SQL.Append (filename) String CSVData = NULL;

// バ ファ ファ ファ CSV デ デ タ String type に に 変 / // csvdata = Exchangechar (SQL.TOString ()); csvdata = Exchangechar (SQL.TOString ());

/ ** * ファ ファ ファ 出 * /

Bufferedwriter Writer; Writer = NULL; String OutputFileName = NULL;

る ファ ファ る る;;;;;;;;;;;;;;;;;

Writer = New BufferedWriter (New FileoutPutStream (OutputFileName), "EUC_JP");

Writer.write (csvdata, 0, csvdata.length ());

IF (writer! = null) {writer.flush (); Writer.close ();

// Output Download Document INT ILENGTH; Response.setContentType ("Application / Musicnavi-CSV; Charset = X-SJIS"); Response.setHeader ("Content-Disposition", "Attachment; FileName = /" "WWW" ".csv /"); // Response.setContentType (ContentType "; Charset = UTF-8"); /*Response.setContentType ("Application/OCT-STREAM ";*/ //Response.addheader ( "Content-Disposition", "attachment; filename =" fName); ServletOutputStream sos = response.getOutputStream (); FileInputStream fos = new FileInputStream ( "aaa.txt"); iLength = fos.available (); byte b [] = New byte [ilength]; // read file content fos.read (b);

Sos.write (b); sos.close (); fos.close ();

Ret = true;

} catch (exception e) {log.error ("exception !!" E.getMessage ()); throw new exception (E.getMessage ());}

Return Ret;}

/ ** * Method Exchangechar. * @Param string * @return string * / public static string line = "; char [] ch = str.tochararray ();

Char [] [] sjtomsj; sjtomsj = new char [8] [2]; sjtomsj [0] [0] = 0xff3c; sjtomsj [0] [1] = 0x2016; sjtomsj [1] [0] = 0xff5e; sjtomsj [ 1] [1] = 0x301c; sjtomsj [2] [0] = 0x2225; sjtomsj [2] [1] = 0x2016; sjtomsj [3] [0] = 0xff0d; sjtomsj [3] [1] = 0x2212; sjtomsj [ 4] [0] = 0xffe0; sjtomsj [4] [1] = 0x00a2; sjtomsj [5] [0] = 0xffe1; sjtomsj [5] [1] = 0x00A3; sjtomsj [6] [0] = 0xffe2; sjtomsj [ 6] [1] = 0x00ac; sjtomsj [7] [0] = 0x2015; sjtomsj [7] [1] = 0x2014;

Line = String.copyValueof (CH);

For (int i = 0; i

转载请注明原文地址:https://www.9cbs.com/read-62488.html

New Post(0)