您的位置:首页 > 其它

[IO]——纯文本读取

2016-04-07 19:47 260 查看
/**
* 纯文本读取
* @author Administrator
*
*/
public class demo01 {
public static void main(String[] args) {
//创建源
File src=new File("E:/others/good.txt");
//选择流
Reader reader=null;
try {
reader=new FileReader(src);
//读取文件
char[] flush=new char[100];
int len=0;
while(-1!=(len=reader.read(flush))){
//字符数组转换为字符串
String str=new String(flush, 0, len);
System.out.println(str);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println("源文件不存在!");
} catch (IOException e) {
e.printStackTrace();
System.out.println("文件读取失败!");
}finally {
try {
if (null != reader) {
reader.close();
}
} catch (Exception e2) {
System.out.print("关闭失败!");
}
}

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  IO 纯文本读取