public static void main(String[] args) throws Exception { FileInputStream in = new FileInputStream("c:\\aa.txt"); int i = 0; while ((i = in.read()) != -1) { System.out.println((char)i); } //========================================== byte[] b = new byte[10]; i = 0; while ((i = in.read(b)) != -1) { System.out.println(new String(b, "gb2312")); } in.close(); }上面两种方法你用哪一种呢? 第一种肯定会出现乱码的。因为每次读一个字节.第二种当汉字前单字节为2的倍数时不会出现乱码.
java.io.Reader ->java.io.InputstreamReader ->java.io.FileReader(java.io.FileWriter)
不知道说的对不对!
如果它们可以作用于中文字符,那为什么还要FileReader/FileWriter?
FileInputStream in = new FileInputStream("c:\\aa.txt");
int i = 0;
while ((i = in.read()) != -1) {
System.out.println((char)i);
}
//==========================================
byte[] b = new byte[10];
i = 0;
while ((i = in.read(b)) != -1) {
System.out.println(new String(b, "gb2312"));
}
in.close();
}上面两种方法你用哪一种呢?
第一种肯定会出现乱码的。因为每次读一个字节.第二种当汉字前单字节为2的倍数时不会出现乱码.
{
try {
String temp = str;
byte[] temp_bt = temp.getBytes("ISO8859-1");
String temp_p = new String(temp_bt);
return temp_p;
}catch (Exception e)
{
System.out.println(e.getMessage());
}
return "null";
}把乱码转中成中文