java中IO整理

1.将数据从外存中读取到内存中的称为输入流,将数据从内存写入外存中的称为输出流。


2.标准的文件读写程序:

public static void main(String[] args) {
		File file = new File("Test.txt");
		try {
			FileInputStream fis = new FileInputStream(file);
			InputStreamReader isr = new InputStreamReader(fis, "gbk");
			BufferedReader br = new BufferedReader(isr);
			String line;
			while((line=br.readLine()) != null){
				System.out.println(line);
			}
			br.close();
			isr.close();
			fis.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		File nfile = new File("new_Test.txt");
		try {
			FileOutputStream fos = new FileOutputStream(nfile);
			OutputStreamWriter osw = new OutputStreamWriter(fos, "gbk");
			BufferedWriter bw = new BufferedWriter(osw);
			bw.write("你是不是我写入的");
			bw.close();
			osw.close();
			fos.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}	

3.父到子:Object->io.Reader(字符流)->io.InputStreamReader->io.FileReader
  父到子:Object->io.Reader(字符流)->io.BufferedReader
  父到子:Object->io.InputStream(字节流)->FilterInputStream->io.BufferedInputStream
  父到子:Object->io.InputStream(字节流)->io.FileInputStream(获得输入的字节)

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值