public class TranStreamDemo2 {
/**
* @param args
* 将一串字符串按指定编码表输入到文本中
* @throws IOException
*/
public static void main(String[] args) throws IOException {
read_1();
read_2();
read_3();
write_3();
write_1();
write_2();
}
public static void read_3() throws IOException, IOException {
InputStreamReader isr=new InputStreamReader(new FileInputStream("E:\\gbk_2.txt"),"UTF-8");
char[] ch=new char[1024];
int len=isr.read(ch);
System.out.println(new String(ch,0,len));
}
public static void read_2() throws IOException, IOException {
InputStreamReader isr=new InputStreamReader(new FileInputStream("E:\\utf_3.txt"),"GBK");
char[] ch=new char[1024];
int len=isr.read(ch);
System.out.println(new String(ch,0,len));
}
public static void read_1() throws IOException {
FileReader fr=new FileReader("E:\\utf_3.txt");
char[] ch=new char[1024];
int len=fr.read(ch);
System.out.println(new String(ch,0,len));
}
public static void write_3() throws IOException, IOException {
OutputStreamWriter osw=new OutputStreamWriter(new FileOutputStream("E:\\utf_3.txt"),"UTF-8");
osw.write("你好");
osw.close();
}
public static void write_2() throws FileNotFoundException, IOException {
OutputStreamWriter osw=new OutputStreamWriter(new FileOutputStream("E:\\gbk_2.txt"),"gbk");
osw.write("你好");
osw.close();
}
public static void write_1() throws IOException {
FileWriter fw=new FileWriter("E:\\gbk_1.txt");
fw.write("你好");
fw.close();
}
}
将一串字符串按指定编码表输入到文本中
最新推荐文章于 2021-12-13 18:33:20 发布