字符流与字节流
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(); // 强制刷新缓冲区
}
}