Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在BufferedReader流中检测\n_Java_Bufferedreader_Linefeed - Fatal编程技术网

Java 在BufferedReader流中检测\n

Java 在BufferedReader流中检测\n,java,bufferedreader,linefeed,Java,Bufferedreader,Linefeed,我有一个字符串,看起来像这样: "foobar\n" 我使用BufferedReader读取此字符串。我需要能够检测是否有一个新的行存在。我使用的是readLine,但我切换到了read,这样我就可以抓住\n但运气不好。我尝试了这个方法,效果很好: while((charT = reader.read()) != -1) { if(charT != '\n') System.out.println("Carriage Return!"); } 这篇文章可能会帮助你定义“运气不佳”。使用rea

我有一个字符串,看起来像这样:

"foobar\n"

我使用BufferedReader读取此字符串。我需要能够检测是否有一个新的行存在。我使用的是readLine,但我切换到了read,这样我就可以抓住\n但运气不好。

我尝试了这个方法,效果很好:

while((charT = reader.read()) != -1) {
if(charT != '\n')
System.out.println("Carriage Return!");
}

这篇文章可能会帮助你定义“运气不佳”。使用
read
将返回换行符,因此您看到的问题一定是代码中的其他内容造成的。我正在将read中的所有字符推入数组,但在数组中没有看到\n。我现在明白了,我使用了错误的读取函数。谢谢你的帮助。