A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© Cubase 中级黑马   /  2016-9-25 18:51  /  378 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

public class FileOutputStreamDemo3 {
        public static void main(String[] args) {
                File file = new File("c:\\file.txt");
                //定义FileOutputStream的引用
                FileOutputStream fos = null;
                try {
                        //创建FileOutputStream对象
                        fos = new FileOutputStream(file);
                        //写出数据
                        fos.write("abcde".getBytes());
                } catch (IOException e) {
                        System.out.println(e.toString() + "----");
                } finally {
                        //一定要判断fos是否为null,只有不为null时,才可以关闭资源
                        if (fos != null) {
                                try {
                                        fos.close();
                                } catch (IOException e) {
                                        throw new RuntimeException("");
                                }
                        }
                }
        }
}

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马