search

Home  >  Q&A  >  body text

Java exports csv file through header with garbled characters

java Export csv file with garbled characters through header

try{
               
                context.response().putHeader("Content-type", "text/csv; charset=UTF-8")
                        .putHeader("Content-Disposition", "attachment;filename="+csv_name+".csv;charset=utf-8")
                        .putHeader("write","\ufeff")
                        .end(string);

            }catch (Exception e){
                e.printStackTrace();
            }
巴扎黑巴扎黑2746 days ago676

reply all(2)I'll reply

  • 天蓬老师

    天蓬老师2017-05-17 10:00:38

    utf8 csv files need to have BOM header
    Reference link http://blog.csdn.net/youzhoul...

    reply
    0
  • 迷茫

    迷茫2017-05-17 10:00:38

    Changing UTF-8 to GBK should eliminate garbled characters. CSV is a bit tricky

    reply
    0
  • Cancelreply