国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

IO流_FileOutputStream寫出數(shù)據(jù)加入異常處理

2019-11-10 19:43:58
字體:
供稿:網(wǎng)友
package cn.itcast_01;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;/* * 加入異常處理的字節(jié)輸出流 */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();		// }		// 改進(jìn)版		// 為了在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 block			e.printStackTrace();		} catch (IOException e) {			e.printStackTrace();		} finally {			// 如果fos不為null,才需要close()			if (fos != null) {				// 為了保證close()一定會執(zhí)行,就放到這里了				try {					fos.close();				} catch (IOException e) {					e.printStackTrace();				}			}		}	}}
發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 德钦县| 海口市| 梨树县| 鹤山市| 盐城市| 健康| 昆山市| 田东县| 缙云县| 平乡县| 屏东市| 固镇县| 广德县| 察雅县| 曲周县| 柳林县| 诏安县| 东山县| 温泉县| 和平县| 台山市| 石林| 古丈县| 游戏| 嘉兴市| 罗城| 绍兴县| 光山县| 琼结县| 涿鹿县| 嫩江县| 彭泽县| 井冈山市| 宾阳县| 新安县| 东至县| 竹北市| 合山市| 射洪县| 安丘市| 秭归县|