Java的IO流

I/O 流:处理设备之间的数据的传输。Input是输入,Output是输出。输入输出指的是内存。所以Input对应的是Reader,指的是从外部读取数据进入内存(程序);Output对应的是Writer,指的是将内存中的数据写到外部;

分类:字节流(InputStream/OutputStream),字符流(Reader/Writer);
字符流专门用于处理文本文件,读取和写入字符使用

使用代码:
public class Main {
    public static void main(String[] args) {

        //路径path
        String path1 = "D:\\study\\Java\\JavaSE基础\\TMP\\Test.txt";
        String path2 = "D:\\study\\Java\\JavaSE基础\\TMP\\Test2.txt";
        //1.输入字节流

        //FileStream.ReadFile(path1);

        //2.输出字节流
/*        byte[] bytes = new byte[]{'a','b','c'};
        FileStream.WriteFile(path1,bytes);*/

        //3.输入字符流
        //FileReaderAndWriter.ReadFile(path2);

        //4.输出字符流
        String value = "我是Java";
//        FileReaderAndWriter.WriteFile(path2,value);

        //5.输入字节流转字符流
/*        try {
            InputStreamReader reader = new InputStreamReader(new FileInputStream(new File(path1)));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

        //6.输出字节流转字符流
        try {
            OutputStreamWriter writer= new OutputStreamWriter(new FileOutputStream(new File(path1)));
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }*/

        //7.缓冲输入字符流
        //BuffedReaderAndWriter.ReadFile(path1);

        //8.缓冲输出字符流
        //BuffedReaderAndWriter.WriteFile(path2,value);

        //9.利用缓冲流复制文件
        //BuffedReaderAndWriter.copyFile(path1,path2);

        //10.对象输出流,可以利用流持久化对象,但要求对象必须实现序列化接口Serializable接口
//        People p = new Peop

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值