java - 为什么 BufferedReader::readLine 挂在 EOF 上?
问题描述
我有一些 Java 8 代码试图将文件的内容(包括换行符)读入一个字符串;这是胆量:
static private void fn( BufferedReader reader ) throws IOException {
StringBuilder builder = new StringBuilder( 1000000 );
String line = null;
while ( ( line = reader.readLine() ) != null ) {
builder.append( line ).append( '\n' );
System.err.println( line );
}
String text = builder.toString();
...
}
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader( new InputStreamReader( System.in ) );
fn( reader );
}
我在 Eclipse 中的运行配置下运行它,它System.in
从一个文件(它确实以 EOF 结尾)重定向,并且打印语句确认这些行确实被读取,但是一旦读取超过最后一行,它挂在 Eclipse 调试器中。
以这种方式从其他文件中读取我没有遇到这个问题;为什么现在?
解决方案
推荐阅读
- amazon-web-services - 从本地将数据库与 Amazon VPC 连接
- sql - 如何将字符串与动态数字或字符连接起来,并在 MS Access db 的 WHERE 和 JOIN 子句中使用它
- c# - Xamarin Forms iOS C# 捕获异常不起作用
- ios - UICollectionView 无法识别点击
- angular - Angular - mat-paginator 没有出现在 mat-table 中
- python - 映射 Django URL 时遇到问题
- maven - Maven + Surefire + @RunWith(JUnitPlatform.class) 注解
- github - 如何使用 github API 获取分支信息
- node.js - 为什么异步文件读取比同步文件读取慢?
- python - 使用 pandas read_excel 丢失浮点数据类型的精度