JAVA_IO_字符流读取文件内容

来源:互联网 发布:red hat linux 安装vm 编辑:程序博客网 时间:2024/04/28 18:58
package com.class0417_1;import java.io.*;/** * @author Administrator * 功能:字符流读取文件内容 */public class Test_zifukiu_read {public static void main(String[] args) throws IOException {//Way1();Way2();}//方法一static void Way1() throws IOException{int b;File file = new File("C:/a.txt");FileInputStream  inputStream = new FileInputStream (file);InputStreamReader inputStreamReader = new InputStreamReader(inputStream);while((b=inputStreamReader.read())!=-1){System.out.print((char)b);}//关闭资源inputStreamReader.close();}static void Way2() throws IOException{char[] str = new char[1000];File file = new File("C:/a.txt");FileInputStream  inputStream = new FileInputStream (file);InputStreamReader inputStreamReader = new InputStreamReader(inputStream);int length = inputStreamReader.read(str);System.out.println(str);//关闭资源inputStreamReader.close();}}

1 0
原创粉丝点击