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();
}
}
JAVA_IO_字符流读取文件内容
最新推荐文章于 2023-09-18 00:46:05 发布