public class IO01 {
public static void main(String[] args) throws IOException {
FileOutputStream fos = new FileOutputStream("code\\fos.txt");//在后端隐式执行File文件的操作
FileOutputStream fos2 = new FileOutputStream(new File("code\\fos.txt"));//已显式执行File文件操作,所以与上者功能一样
byte[] bys="fadbvcx".getBytes();//将字符串转化为字符数组
fos.write(bys);
}
}

此博客展示了如何使用Java的FileOutputStream进行文件操作,创建并写入字节数组到'fos.txt'文件中。代码中通过两种方式实例化FileOutputStream,尽管方式不同但功能相同。
2743

被折叠的 条评论
为什么被折叠?



