2.1其他流输出姓名学号

这篇博客展示了如何使用Java进行文件输出,分别通过`FileOutputStream`和`BufferedWriter`实现将姓名和学号写入到'word.txt'文件中。示例代码包括创建文件对象、建立文件输出流、将内容写入文件并关闭流的过程。
摘要由CSDN通过智能技术生成

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class wjzjl {
public static void main(String[] args) {
File f=new File(“word.txt”); //创建文件对象
try {
FileOutputStream fo=new FileOutputStream(f);//创建文件输出流,把fo中的内容写道文件中
byte byt[]=“姓名:齐燕博 学号:20202204061”.getBytes();//创建一个byte数组,利用getbytes函数将字符串转化为字符
fo.write(byt); //把byt的内容写道文件中
fo.close(); //关闭流
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
}在这里插入图片描述

package KOBE;

import java.io.BufferedWriter;
import j

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值