?????????????????????????????Щ????

 

public class IOTest {
private static String str = "????";
public static void main(String[] args) throws Exception {
System.out.println(System.getProperty("file.encoding"));
testChar();
printBytes(str.getBytes("utf-8"));
printBytes(str.getBytes("unicode"));
printBytes(str.getBytes("gb2312"));
printBytes(str.getBytes("iso8859-1"));
printBytes("ABC".getBytes("iso8859-1"));
byte[] bytes = {-28?? -72?? -83?? -26?? -106?? -121};
System.out.println(getStringFromBytes(bytes??"utf-8"));
byte[] bytes1 = { -2??-1??78?? 45?? 101?? -121};
System.out.println(getStringFromBytes(bytes1??"unicode"));
System.out.println(new String(bytes1));
readBytesFromFile("C:/D/charset/utf8.txt");
readBytesFromFile("C:/D/charset/gb2312.txt");
readStringFromFile("C:/D/charset/utf8.txt"??"utf8");
readStringFromFile("C:/D/charset/gb2312.txt"??"gb2312");
}
public static void testChar() throws Exception {
char c = '??';
int i = c;
System.out.println(i);
System.out.println("u4E2D");
printBytes("??".getBytes("unicode"));
}
public static void printBytes(byte[] bytes ) {
for(int i=0; i<bytes.length;i++){
System.out.print(" " + bytes[i]);
}
System.out.println("");
}
public static String getStringFromBytes(byte[] bytes??String charset ) throws Exception {
return new String(bytes??charset);
}
public static void writeTofile(byte[] bytes ) {
for(int i=0; i<bytes.length;i++){
System.out.print(" " + bytes[i]);
}
System.out.println("");
}
public static void readBytesFromFile(String fileName ) throws Exception {
File f = new File(fileName);
FileInputStream fin = new FileInputStream(f);
byte[] readBytes = new byte[10];
while (true) {
if (fin.available() >= 10) {
fin.read(readBytes);
for (byte b : readBytes) {
System.out.print(b + " ");
}
} else {
byte[] lastbits = new byte[fin.available()];
fin.read(lastbits);
for (byte b : lastbits) {
System.out.print(b + " ");
}
break;
}
}
System.out.println("");
fin.close();
}
public static void readStringFromFile(String fileName??String charset) throws Exception {
File file = new File(fileName);
FileInputStream fis = new FileInputStream(file);
InputStreamReader fr = new InputStreamReader(fis??charset);
BufferedReader br = new BufferedReader(fr);
String line;
while ((line=br.readLine()) != null){
System.out.println(line);
}
br.close();
fr.close();
fis.close();
}
}

????Java???????????????Java?У?????????????????Unicode???д洢?????????????????
??????????????


char c = '??';
int i = c;
System.out.println(i);    //20013
System.out.println("u4E2D"); //??
printBytes("??".getBytes("unicode")); //-2 -1 78 45

????20013?????16?????4E2D?? 4E2D?????10?????78 45??