package com.csii.syn;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class Test {
public static void main(String[] args) throws IOException {
// InputStream is = new FileInputStream("D:/test.txt");
// System.out.println(fis.available());
// byte[] send = new byte[5];
// System.out.println(new String(send,"UTF-8"));
// fis.read(send);
// System.out.println(new String(send,"GBK"));
// fis.close();
// byte[] bytes1 = new byte[2];
// int len = -1;
// while((len = is.read(bytes1)) != -1) {
// System.out.println(len);
// }
// System.out.println("1a.第一行".getBytes("GBK"));
// byte[] bytes = "1a.第一行".getBytes("ASCII");
// for (int i = 0; i < bytes.length; i++) {
// System.out.println(bytes[i]);
// }
OutputStream os = new FileOutputStream("D:/test1.txt");
os.write("ab我尔".getBytes("UTF-8"));//ISO-8859-1
InputStream is = new FileInputStream("D:/test1.txt");
byte[] bytes = new byte[3];
int len = -1;
String str = null;
is.read(bytes);
if(bytes[0]==-17 && bytes[1]== -69 && bytes[2] == -65) {
System.out.println("是UTF-8编码");
} else {
System.out.println("不是");
}
while((len = is.read(bytes)) != -1) {
System.out.println("len:"+len);
System.out.println(new String(bytes, 0, len, "ISO-8859-1"));
}
System.out.println("中文");
byte[] by = new byte[3];
by[0] = 97;
by[1] = 98;
by[2] = 127;
System.out.println(new String(by,"ISO-8859-1"));
}
}
评论4
最新资源