try {
FileInputStream fi = new FileInputStream("f:/3.txt");
BufferedReader bs = new BufferedReader(new InputStreamReader(fi));
try {
while(bs.readLine()!=null){
String str = bs.readLine();
System.out.println(str);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
txt读取字符串(为实习生作的例子)
最新推荐文章于 2024-08-20 04:38:41 发布
本文提供了一个使用Java进行文件读取的简单示例代码,通过FileInputStream与BufferedReader组合来逐行读取文本文件,并打印出每行的内容。该示例展示了如何处理常见的异常,如FileNotFoundException和IOException。
&spm=1001.2101.3001.5002&articleId=83208683&d=1&t=3&u=de08f111151b4abeaf1866d175eec629)
1万+

被折叠的 条评论
为什么被折叠?



