1234567891011121314151617181920212223242526272829303132333435 |
- package J20250725;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.IOException;
- /**
- * @author WanJl
- * @version 1.0
- * @title Demo01_FileOutputStream
- * @description
- * @create 2025/7/25
- */
- public class Demo01_FileOutputStream {
- /*
- FileNotFoundException 文件不存在异常
- IOException 不能输入或输出异常,是FileNotFoundException的父类
- */
- public static void main(String[] args) throws IOException {
- //1、创建字节输出流对象
- FileOutputStream fos=new FileOutputStream("D:/2025年7月25日.txt");
- //如果文件不存在,会帮我们创建
- //如果文件存在,会覆盖文件,会把文件内容清空
- //把指定的字节输入到此文件输出流
- fos.write(65);
- fos.write(66);
- for (int i = 0; i < 100; i++) {
- fos.write(i);
- }
- //无论前面做了什么,只要创建了IO流对象,就一定要调用的一个方法:close()
- //关闭流
- fos.close();
- }
- }
|