失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > 解决java以UTF-8输出中文时 Excel打开多语言文件乱码但是记事本打开却正常的问题

解决java以UTF-8输出中文时 Excel打开多语言文件乱码但是记事本打开却正常的问题

时间:2024-01-07 20:31:33

相关推荐

解决java以UTF-8输出中文时 Excel打开多语言文件乱码但是记事本打开却正常的问题

解决java以UTF-8输出中文时,Excel打开多语言文件乱码但是记事本打开却正常的问题

public static boolean exportCsv(File file, List dataList){boolean isSucess=false;FileOutputStream out=null;OutputStreamWriter osw=null;BufferedWriter bw=null;try {out = new FileOutputStream(file);//追加BOM标识,否则excel打开会乱码out.write(0xef);out.write(0xbb);out.write(0xbf);osw = new OutputStreamWriter(out,"utf-8");bw =new BufferedWriter(osw);if(dataList!=null && !dataList.isEmpty()){for(int i=0;i<dataList.size();i++){bw.append((String)dataList.get(i)).append("\r");}}isSucess=true;} catch (Exception e) {isSucess=false;}finally{if(bw!=null){try {bw.close();bw=null;} catch (IOException e) {e.printStackTrace();} }if(osw!=null){try {osw.close();osw=null;} catch (IOException e) {e.printStackTrace();} }if(out!=null){try {out.close();out=null;} catch (IOException e) {e.printStackTrace();} }}return isSucess;}

如果觉得《解决java以UTF-8输出中文时 Excel打开多语言文件乱码但是记事本打开却正常的问题》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。