请高人指点:小弟写的代码 :
String name = new String();
name="jsp/onclick=登陆";ByteArrayInputStream bais= new ByteArrayInputStream(name.getBytes());Properties pro = new Properties ();pro.load(bais);Set functionIsNew =pro.keySet();
Object[] keys = functionIsNew.toArray();
for(int i=0;i<keys.length;i++)
{
String line=(String)pro.get(keys[i]);
System.out.println(line);
}********************************运行后
line=??? 期望的结果line=登陆望那位高人指点小弟!先谢了!
String name = new String();
name="jsp/onclick=登陆";ByteArrayInputStream bais= new ByteArrayInputStream(name.getBytes());Properties pro = new Properties ();pro.load(bais);Set functionIsNew =pro.keySet();
Object[] keys = functionIsNew.toArray();
for(int i=0;i<keys.length;i++)
{
String line=(String)pro.get(keys[i]);
System.out.println(line);
}********************************运行后
line=??? 期望的结果line=登陆望那位高人指点小弟!先谢了!
因为一个汉字是两个byte
// Read properties file.
Properties properties = new Properties();
try {
properties.load(new FileInputStream("filename.properties"));
} catch (IOException e) {
}
// Write properties file.
try {
properties.store(new FileOutputStream("filename.properties"), null);
} catch (IOException e) {
}Here is an example of the contents of a properties file:
# a comment
! a comment
a = a string
b = a string with escape sequences \t \n \r \\ \" \' \ (space) \u0123
c = a string with a continuation line \
continuation line
d.e.f = another string
我现在用 mySmartUpload
file=mySmartUpload.getFiles().getFile(0);
ByteArrayInputStream bais= new ByteArrayInputStream(file.getContentString().getBytes());Properties pro = new Properties ();pro.load(bais);
Map mu =(Map)pro;然后把 mu中的数据写入数据库中。 出现了乱码! 多谢你的指点!我用你的方法试试
{
String s2;
String s1 = s;
try{
byte abyte0[] = s1.getBytes("ISO8859-1");
s2 = new String(abyte0);
return s2;
}
catch(Exception e){
System.err.println(e);
return "";
}
}
ByteArrayInputStream bais= new ByteArrayInputStream(file.getContentString().getBytes("ISO8859-1"));
getBytes("GBK") 我都试过了
把Properties源代码改一下,然后重新编译一下就行了。在读取文件的那个地方加一个编码,比如GBK,因为这个文件中默认是以iso8859来进行文件读取的,所以比较麻烦。
你可以把这些源代码拷贝出来,把它变成自己的文件就行了。我是自己写了一个PropertiesUtil文件。
1) 所有的jsp页面指定字符编码方式,如:Charest=gb2312,Charest=UTF-8等等
2) 在应用服务器中的server.xml方件中找到设置服务器端口的行,一般是这样开头:”<Connector port="8080"”,
3) 在找到的行"<Connector"开头的字符串后加上:URIEncoding="UTF-8" ,保存文件
--------------------------------------------------------------------------
jsp页面有乱码解决方法 所有的jsp页面指定字符编码方式,如:Charest=gb2312,Charest=UTF-8等等
<%@ page contentType="text/html; charset=UTF-8">
--------------------------------------------------------------------------
jsp单个中文参数乱码解决方法 用这个转换一下:
<%!String trans(String chi)
{
string result =null;
byte temp[];
temp=chi.getBytes("iso=8859-1");
result= new String(temp);
}
%>
或者直接这样:
<%
request.setCharacterEncoding("UTF-8");
out.println(request.getParameter("参数ID")
%>
--------------------------------------------------------------------------