读出数据流到byte[]后转成String时用
new String(byte[], "UTF-8")的方法 或者"ISO-8859-1"编码!
不知道行不行?
new String(byte[], "UTF-8")的方法 或者"ISO-8859-1"编码!
不知道行不行?
解决方案 »
- 大家帮忙看一下我的java小程序,为何jpanel上没有显示东西
- static
- Map<String, String>和HashMap<String, String>这2个有什么不同
- 如何输出中国格式的时间?
- Runtime.getRuntime().exec(cmd);时出现cmd窗口不消失的问题
- 我确实找不到这个程序有什么错误,可是编译器总是报错?
- 大家好!!小弟有一个问题请教!
- jbuilder7中没有dbgrid之类的组件了吗?jbuilder5是有的
- 如何通过菜单切换同一对象下jpanel。有何方法,如果有代码示范,就更好了
- 我该怎么办
- JBuilder9下Applet执行出错的问题
- 求正则表达式,形如:f(Max,A012[1],TAB01,A001[1],>,100) f(Max,A012[1],TAB01,A001[1],=,'aa')
FileWriter letters=new FileWriter("c:\\ddd.txt");
String uni;
while(!eof){
String line=buff.readLine(); if(line==null) eof=true;
else
{
uni = new String(line.getBytes(),"GB2312").trim();
letters.write(uni);
}
}或者 int inByte=text.read();
while(inByte!=-1){
if(inByte==10||inByte==13){}
else letters.write(inByte);
inByte=text.read();
}都不行:(
package Util;/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/public class ToolKit {
public static String[] split(String str, String div, boolean isRegular) {
String result[] = null; //返回结果集合
String substr; if (str == null || div == null) {
return (null);
} if ((str = str.trim()).length() == 0)
return (new String[]{str}); int cur = 0,
cnt = 0,
prv = cur,
end; while (cur < str.length()) { if ((end = str.indexOf(div, cur)) < 0) {
end = str.length();
} substr = str.substring(cur, end);
if (isRegular) {
cnt += stringCount(substr, "(");
cnt -= stringCount(substr, ")");
}
if (isRegular == false || cnt == 0 || end == str.length()) {
substr = str.substring(prv, end);
if (result == null) {
result = new String[]{new String(substr)};
} else {
int len = result.length;
String array[] = new String[len + 1]; for (int i = 0; i < len; i++)
array[i] = result[i]; result = array; result[len] = new String(substr);
}
}
cur = end + div.length();
if (isRegular == false || cnt == 0)
prv = cur;
}
return (result);
}
private static int stringCount(String str, String div) {
int cnt = 0;
int pos = 0;
while ((pos = str.indexOf(div, pos)) >= 0) {
pos += div.length();
cnt++;
}
return cnt;
}
public static String[] split(String str, String div) {
return split(str, div, false);
}
public static void main(String[] args) {
}
}
1、ANSI,不用说了
2、UNICODE,头两个字节内容为 0xFF 0xFE,对应为 UTF-16LE
3、UNICODE big endian,文字同样为UNICODE编码,只是字节顺序同2相反,以 0xFE 0xFF 开头,对应为 UTF-16BE
4、UTF-8,这种编码方式在<JAVA核心技术 I>上面有讲述,头三个字节为0xEF 0xBB 0xBF, 对应为 UTF-8处理过程中先读出前三个字节内容判断出编码方式,然后再进行转换。