java学习笔记之——文件输出流

import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Scanner;

public class FileOutputStreamDemo {

    public static void main(String[] args) {


        Scanner scanner = new Scanner(System.in);


        FileOutputStream fos = null;
        try {

            fos = new FileOutputStream("文件路径");

            String str = scanner.nextLine();

            fos.write(str.getBytes());

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {

                fos.close();
                scanner.close();
            } catch (IOException e) {

                e.printStackTrace();
            }
        }

    }

}
发布了13 篇原创文章 · 获赞 8 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/JOHNEW/article/details/69388842