将一串字符串按指定编码表输入到文本中

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();
		
	}

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值