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

首頁 > 學院 > 開發設計 > 正文

IO流_FileInputStream讀取數據一次一個字節數組

2019-11-10 18:44:26
字體:
來源:轉載
供稿:網友
package cn.itcast_02;import java.io.FileInputStream;import java.io.IOException;/* * 一次讀取一個字節數組:int read(byte[] b) * 返回其實是實際讀取取的字節個數。  */public class FileInputStreamDemo2 {	public static void main(String[] args) throws IOException {		// 創建字節輸入流對象		// FileInputStream fis = new FileInputStream("fis2.txt");		FileInputStream fis = new FileInputStream("FileOutputStreamDemo.java");		// 讀取數據		// 定義一個字節數組		// 第一次讀取		// byte[] bys = new byte[5];		// int len = fis.read(bys);		// System.out.PRintln(len);		// System.out.println(new String(bys, 0, len));		//		// // 第二次讀取		// len = fis.read(bys);		// System.out.println(len);		// System.out.println(new String(bys, 0, len));		//		// // 第三次讀取		// len = fis.read(bys);		// System.out.println(len);		// System.out.println(new String(bys, 0, len));		//		// // 第四次讀取		// len = fis.read(bys);		// System.out.println(len);		// System.out.println(new String(bys, 0, len));		// // 代碼重復了,用循環改進		// // 但是我不知道循環條件		// len = fis.read(bys);		// System.err.println(len);		// len = fis.read(bys);		// System.err.println(len);		// 如果讀取到的實際數據是-1,就說明沒有數據了		// byte[] bys = new byte[115];		// int len = 0;		// while ((len = fis.read(bys)) != -1) {		// System.out.print(new String(bys, 0, len));		// // System.out.println(new String(bys));//千萬要帶上len的使用		// }		// 最終代碼版		// 數組的長度一般是1024或者1024的整倍數		byte[] bys = new byte[1024];		int len = 0;		while ((len = fis.read(bys)) != -1) {			System.out.print(new String(bys, 0, len));		}		// 釋放資源		fis.close();	}}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 博兴县| 肃宁县| 双城市| 建平县| 高唐县| 昆山市| 佛坪县| 奎屯市| 平邑县| 教育| 隆林| 和田县| 连平县| 万宁市| 梅州市| 钟祥市| 鸡西市| 图木舒克市| 翼城县| 新源县| 漯河市| 栾川县| 吴旗县| 综艺| 锡林郭勒盟| 罗山县| 隆回县| 随州市| 义乌市| 南汇区| 平江县| 永定县| 偏关县| 昭通市| 南康市| 富平县| 莱西市| 宜昌市| 龙州县| 夹江县| 高陵县|