设为首页 加入收藏

TOP

Java通过java.io.FileInputStream读取txt文本
2014-11-23 23:19:39 来源: 作者: 【 】 浏览:9
Tags:Java 通过 java.io.FileInputStream 读取 txt 文本

Java通过java.io.FileInputStream读取txt文本


package com;


import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;


public class TestIO {
public static void main(String[] args) {
FileInputStream in = null;
try {
in = new FileInputStream("test.txt");
int c;
c = in.read();
while (c != -1) {
System.out.print((char) c);
c = in.read();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
System.out.println(e.getMessage());
} finally {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}


其中test.txt内为英文字符串,放在eclipse项目文件夹根目录下,对于中文需要做编码处理。


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Android应对Activity进程被杀死 下一篇Android-屏幕元素层次结构

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: