IO流_FileOutputStream写出数据加入异常处理
来源:互联网 发布:游戏开发用什么软件 编辑:程序博客网 时间:2024/05/01 10:56
package cn.itcast_01;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;/* * 加入异常处理的字节输出流 */public class FileOutputStreamDemo4 {public static void main(String[] args) {// 分开做异常处理// FileOutputStream fos = null;// try {// fos = new FileOutputStream("fos4.txt");// } catch (FileNotFoundException e) {// // TODO Auto-generated catch block// e.printStackTrace();// }//// try {// fos.write("java".getBytes());// } catch (IOException e) {// // TODO Auto-generated catch block// e.printStackTrace();// }//// try {// fos.close();// } catch (IOException e) {// // TODO Auto-generated catch block// e.printStackTrace();// }// 一起做异常处理// try {// FileOutputStream fos = new FileOutputStream("fos4.txt");// fos.write("java2".getBytes());// fos.close();// } catch (FileNotFoundException e) {// e.printStackTrace();// } catch (IOException e) {// e.printStackTrace();// }// 改进版// 为了在finally里能看到该对象,就必须定义到外面,为了访问不出问题,还必须给出初始化值FileOutputStream fos = null;try {// fos = new FileOutputStream("z:\\fos4.txt");fos = new FileOutputStream("fos4.txt");fos.write("java3".getBytes());} catch (FileNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {e.printStackTrace();} finally {// 如果fos不为null,才需要close()if (fos != null) {// 为了保证close()一定会执行,就放到这里了try {fos.close();} catch (IOException e) {e.printStackTrace();}}}}}
0 0
- IO流_FileOutputStream写出数据加入异常处理
- IO流_FileOutputStream写出数据
- IO流_FileOutputStream写出数据实现换行和追加写入
- IO流_FileOutputStream写出数据实现换行和追加写入
- IO流_FileOutputStream写出数据实现换行和追加写入
- 字节流_FileOutputStream类写出
- IO流_FileOutputStream的构造方法
- IO流_FileOutputStream的三个write()方法
- IO流_BufferedOutputStream写出数据
- java学习初探十七之IO流_FileOutputStream
- Java_SE08-文本数据IO操作,异常处理
- 文本数据IO操作 、 异常处理
- IO流---异常处理机制
- IO流--IO异常的处理方式
- IO流(IO异常处理方式)
- IO流FileWriter的IO异常处理
- IO 字符流 FileWriter IO异常的处理 字符数据续写 FileReader 复制原理:
- IO流_随机访问流概述和写出数据
- Celery内存泄露问题分析
- ASP中冒号: 和 下划线_ 的作用
- STM32串口第一个字节丢失解决办法
- Linux Platform驱动模型(二) _驱动方法
- Xamarin Studio build event issue
- IO流_FileOutputStream写出数据加入异常处理
- 全排列Permutations
- response.setContentType()中MIME参数类型总结
- 万亿级数据洪峰下的分布式消息引擎
- mysql存储过程和触发器 --- 一次很有意思的尝试
- P1048 采药
- 通过SQL Server命令行启动及停止SQL服务的方法
- JVM(java 虚拟机)内存设置
- Leetcode——468. Validate IP Address