---
title: "poi 导出excel文件名乱码"
author: "touch_mai"
date: "2010-06-09T16:10:49Z"
tags: ["C", "C#", "C++", "Excel", "IE"]
categories: ["编程语言"]
slug: "poi-excel"
draft: false
lastmod: "2010-06-09T16:10:49Z"
id: 688107
url: "https://touch-mai.iteye.com/blog/688107"
---

乱码是一个经久不衰的问题！
拿个作为例子
一开始 我用
URLEncoder.encode("中文","UTF-8") 在IE8的情况下好使，
以为 这样就行了;
后来发现 在其它浏览器 以及ie的低版本 都会出现乱码的情况
于是乎 就出现了一下的代码！


```java
public static String toUtf8String(String s){
		        StringBuffer sb = new StringBuffer();
		          for (int i=0;i<s.length();i++){
		             char c = s.charAt(i);
		             if (c >= 0 && c <= 255){sb.append(c);}
		           else{
	               byte[] b;
	                try { b = Character.toString(c).getBytes("utf-8");}
	                catch (Exception ex) {
	                    System.out.println(ex);
		                     b = new byte[0];
	                }
		               for (int j = 0; j < b.length; j++) {
	                    int k = b[j];
	                     if (k < 0) k += 256;
	                     sb.append("%" + Integer.toHexString(k).toUpperCase());
		                 }
	            }
	         }
	         return sb.toString();
		    }
```