您当前的位置: 首页 >  Java

ITKEY_

暂无认证

  • 0浏览

    0关注

    732博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Java温故而知新-字符流与字节流区别

ITKEY_ 发布时间:2021-02-16 16:31:10 ,浏览量:0

字符流与字节流

在这里插入图片描述

在这里插入图片描述


8、
package com.yootk.demo;

import java.io.*;

public class YootkDemo {    // 李兴华编程训练营:yootk.ke.qq.com
    public static void main(String[] args) throws Exception {
        File file = new File("H:" + File.separator + "muyan" + File.separator + "vip" + File.separator + "yootk.txt") ;
        if (!file.getParentFile().exists()) {   // 此时文件有父目录
            file.getParentFile().mkdirs() ; // 创建父目录
        }
        OutputStream output = new FileOutputStream(file) ; // 实例化OutputStream抽象类对象
        String message = "www.yootk.com" ; // 此为要输出的数据内容
        // OutputStream类的输出是以字节数据类型为主的,所以需要将字符串转为字节数据类型
        byte data [] = message.getBytes() ; // 将字符串转为字节数句
        output.write(data); // 输出全部字节数组的内容
    }
}

9、
package com.yootk.demo;

import java.io.*;

public class YootkDemo {    // 李兴华编程训练营:yootk.ke.qq.com
    public static void main(String[] args) throws Exception {
        File file = new File("H:" + File.separator + "muyan" + File.separator + "vip" + File.separator + "yootk.txt") ;
        if (!file.getParentFile().exists()) {   // 此时文件有父目录
            file.getParentFile().mkdirs() ; // 创建父目录
        }
        Writer out = new FileWriter(file) ;
        String message = "www.yootk.com" ; // 此为要输出的数据内容
        out.write(message); // 输出全部字节数组的内容
    }
}

10、
package com.yootk.demo;

import java.io.*;

public class YootkDemo {    // 李兴华编程训练营:yootk.ke.qq.com
    public static void main(String[] args) throws Exception {
        File file = new File("H:" + File.separator + "muyan" + File.separator + "vip" + File.separator + "yootk.txt") ;
        if (!file.getParentFile().exists()) {   // 此时文件有父目录
            file.getParentFile().mkdirs() ; // 创建父目录
        }
        Writer out = new FileWriter(file) ;
        String message = "www.yootk.com\n" ; // 此为要输出的数据内容
        out.write(message); // 输出全部字节数组的内容
        out.append("edu.yootk.com") ;
        out.flush(); // 强制刷新缓冲区
    }
}

在这里插入图片描述

关注
打赏
1665243900
查看更多评论
立即登录/注册

微信扫码登录

0.0403s