M
moonhkt
Hi All
I want to display Charset for GB2312 character byte value. Using
codePointAt(i) just for Unicode code.
How to diaplay GB2123 byte value ?
For ²â should be b2e2
For ÊÔ should be cad4
cat temp.txt
TEST1|²âÊÔ1
TEST2|²âÊÔ2
TEST3|²âÊÔ3
import java.io.*;
public class Readfile00 {
public static void main(String[] args)
throws UnsupportedEncodingException {
String icp = "GB2312";
String ifn = "temp.txt";
PrintStream sysout = new PrintStream(System.out, true, icp);
try {
File oFile = new File("out_utf.text");
BufferedWriter out = new BufferedWriter(
new OutputStreamWriter(new FileOutputStream(oFile),icp));
String a = "" ;
char ch ;
Integer val=0;
String hexstr = "";
BufferedReader in = new BufferedReader(
new InputStreamReader(new FileInputStream(ifn), icp));
while (( a = in.readLine()) != null)
{
int n = a.length();
sysout.println(a);
sysout.printf("Length of string is %d%n", n);
sysout.printf("CodePoints in string is %d%n",
a.codePointCount(0,n));
for (int i = 0; i < n; i++) {
ch = a.charAt(i);
val = a.codePointAt(i); // Return Unicode code point
hexstr = Integer.toHexString(val);
Character.UnicodeBlock block = Character.UnicodeBlock.of(ch);
sysout.printf("Chr[%4d] DEC=%5s UTF-16=%5s is %4s %s %n", i,
val, hexstr, a.charAt(i),block);
//byte bv = (byte) ch;
//System.out.println("Byte is:=" + bv);
out.write(a.charAt(i));
}
out.newLine();
}
out.close() ;
System.out.printf("File %s\n", oFile);
} catch (IOException e) {
System.out.println(e);
}
}
}
I want to display Charset for GB2312 character byte value. Using
codePointAt(i) just for Unicode code.
How to diaplay GB2123 byte value ?
For ²â should be b2e2
For ÊÔ should be cad4
cat temp.txt
TEST1|²âÊÔ1
TEST2|²âÊÔ2
TEST3|²âÊÔ3
import java.io.*;
public class Readfile00 {
public static void main(String[] args)
throws UnsupportedEncodingException {
String icp = "GB2312";
String ifn = "temp.txt";
PrintStream sysout = new PrintStream(System.out, true, icp);
try {
File oFile = new File("out_utf.text");
BufferedWriter out = new BufferedWriter(
new OutputStreamWriter(new FileOutputStream(oFile),icp));
String a = "" ;
char ch ;
Integer val=0;
String hexstr = "";
BufferedReader in = new BufferedReader(
new InputStreamReader(new FileInputStream(ifn), icp));
while (( a = in.readLine()) != null)
{
int n = a.length();
sysout.println(a);
sysout.printf("Length of string is %d%n", n);
sysout.printf("CodePoints in string is %d%n",
a.codePointCount(0,n));
for (int i = 0; i < n; i++) {
ch = a.charAt(i);
val = a.codePointAt(i); // Return Unicode code point
hexstr = Integer.toHexString(val);
Character.UnicodeBlock block = Character.UnicodeBlock.of(ch);
sysout.printf("Chr[%4d] DEC=%5s UTF-16=%5s is %4s %s %n", i,
val, hexstr, a.charAt(i),block);
//byte bv = (byte) ch;
//System.out.println("Byte is:=" + bv);
out.write(a.charAt(i));
}
out.newLine();
}
out.close() ;
System.out.printf("File %s\n", oFile);
} catch (IOException e) {
System.out.println(e);
}
}
}