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

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

IO流_FileInputStream讀取數(shù)據(jù)

2019-11-10 22:56:30
字體:
供稿:網(wǎng)友
package cn.itcast_02;import java.io.FileInputStream;import java.io.IOException;/* * 字節(jié)輸入流操作步驟: * 		A:創(chuàng)建字節(jié)輸入流對象 * 		B:調(diào)用read()方法讀取數(shù)據(jù),并把數(shù)據(jù)顯示到控制臺 * 		C:釋放資源 * 讀取數(shù)據(jù)方式: * 		A:int read():一次讀取一個字節(jié) * 		B:int read(byte[] b):一次讀取一個字節(jié)數(shù)組 */public class FileInputStreamDemo {	public static void main(String[] args) throws IOException {		// FileInputStream(String name)		// FileInputStream fis = new FileInputStream("fis.txt");		FileInputStream fis = new FileInputStream("FileOutputStreamDemo.java");		// 調(diào)用read()方法讀取數(shù)據(jù),并把數(shù)據(jù)顯示到控制臺		// 第一次讀取		// int by = fis.read();		// System.out.PRintln(by);		// System.out.println((char) by);		//		// // 第二次讀取		// by = fis.read();		// System.out.println(by);		// System.out.println((char) by);		//		// // 第三次讀取		// by = fis.read();		// System.out.println(by);		// System.out.println((char) by);		//		// //而我們發(fā)現(xiàn)代碼的重復(fù)度很高,所以我們要用循環(huán)改進(jìn)		// //而用循環(huán),取麻煩的事情是如何用循環(huán)控制條件呢?		// // 第四次讀取		// by = fis.read();		// System.out.println(by);		//		// // 第五次讀取		// by = fis.read();		// System.out.println(by);		// 通過測試我們知道你讀取的數(shù)據(jù)量-1,就說明已經(jīng)讀取到了文件的末尾了		// 用循環(huán)改進(jìn)		// int by = fis.read();		// while (by != -1) {		// System.out.println((char) by);		// by = fis.read();		// }		// 取終代碼		int by = 0;		// 讀取,賦值,判斷		while ((by = fis.read()) != -1) {			System.out.print((char) by);		}		// 釋放資源		fis.close();	}}
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 萍乡市| 固原市| 图们市| 双峰县| 锡林郭勒盟| 桑日县| 平湖市| 中牟县| 胶州市| 定兴县| 卢龙县| 威信县| 南昌市| 新津县| 巢湖市| 丰原市| 鹤峰县| 双辽市| 香格里拉县| 化隆| 福安市| 中宁县| 富裕县| 兰溪市| 蒲城县| 松阳县| 长兴县| 庆元县| 武乡县| 浦东新区| 肇庆市| 略阳县| 莒南县| 瑞安市| 榆社县| 新巴尔虎右旗| 泊头市| 鄢陵县| 榆林市| 聂拉木县| 开化县|