有没有会写一个程序,键盘自动输入已经写好的文本文档
用filestream直接读取。
不用键盘输,程序可以能读文本文档。
用文件流直接读入
public static void main(String[] args) {
FileInputStream fs = null;
InputStreamReader r = null;
BufferedReader bf = null;
try {
//测试文件地址
fs = new FileInputStream("D:/tsxk.txt");
//中文一般编码方式UTF-8或者GBK
r = new InputStreamReader(fs, "GBK");
bf = new BufferedReader(r);
//存放内容
String content;
while ((content=bf.readLine())!=null){
System.out.println(content);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (fs != null) {
fs.close();
}
if (r != null) {
r.close();
}
if (bf != null) {
bf.close();
}
}catch (Exception e){
System.out.println("关闭资源时报错!");
e.printStackTrace();
}
}
}