对FileOutputStream/FileInputStream的应用

来源:互联网 发布:数的读法 c语言 编辑:程序博客网 时间:2024/06/06 01:27

这里写图片描述

实现代码如下:

import java.io.*;public class FileStream {    public static void main(String[] args) {        try {            FileOutputStream out = new FileOutputStream("hello.txt");            out.write("I love you Java!".getBytes());            out.close();            byte[] buf = new byte[1024];            File f = new File("hello.txt");            FileInputStream in = new FileInputStream(f);            int len = in.read(buf);            System.out.println(new String(buf, 0, len));            in.close();        } catch (Exception e) {            e.printStackTrace();        }    }}

运行结果如下:
这里写图片描述

hello.txt文件的内容:
这里写图片描述

0 0
原创粉丝点击