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

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

IO流_FileInputStream讀取數(shù)據(jù)一次一個字節(jié)數(shù)組

2019-11-10 18:08:21
字體:
供稿:網(wǎng)友
package cn.itcast_02;import java.io.FileInputStream;import java.io.IOException;/* * 一次讀取一個字節(jié)數(shù)組:int read(byte[] b) * 返回其實是實際讀取取的字節(jié)個數(shù)。  */public class FileInputStreamDemo2 {	public static void main(String[] args) throws IOException {		// 創(chuàng)建字節(jié)輸入流對象		// FileInputStream fis = new FileInputStream("fis2.txt");		FileInputStream fis = new FileInputStream("FileOutputStreamDemo.java");		// 讀取數(shù)據(jù)		// 定義一個字節(jié)數(shù)組		// 第一次讀取		// 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));		// // 代碼重復(fù)了,用循環(huán)改進		// // 但是我不知道循環(huán)條件		// len = fis.read(bys);		// System.err.println(len);		// len = fis.read(bys);		// System.err.println(len);		// 如果讀取到的實際數(shù)據(jù)是-1,就說明沒有數(shù)據(jù)了		// 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的使用		// }		// 最終代碼版		// 數(shù)組的長度一般是1024或者1024的整倍數(shù)		byte[] bys = new byte[1024];		int len = 0;		while ((len = fis.read(bys)) != -1) {			System.out.print(new String(bys, 0, len));		}		// 釋放資源		fis.close();	}}
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 会宁县| 都兰县| 台中市| 恩平市| 南阳市| 土默特左旗| 汝城县| 连平县| 洪泽县| 皋兰县| 连江县| 钦州市| 奎屯市| 依兰县| 安庆市| 望城县| 乐平市| 漯河市| 易门县| 台中市| 民县| 浦东新区| 延吉市| 元阳县| 徐州市| 恩施市| 垣曲县| 中江县| 阿鲁科尔沁旗| 齐河县| 达尔| 五峰| 安多县| 西乡县| 湘潭县| 泽州县| 新田县| 疏勒县| 武义县| 正安县| 瑞丽市|