Java:如何判断文本文件中的一行是否应该为空白?
我正在开发一个项目,在该项目中我必须读取语法文件(将其分解为我的数据结构),目标是能够生成随机的“DearJohnLetter”。
我的问题是,在读取 .txt 文件时,我不知道如何确定该文件是否应该是完全空白的行,这对程序不利。
这是文件部分的示例,我如何判断下一行是否应该是空行? (顺便说一句,我只是使用缓冲阅读器)谢谢!
<start>
I have to break up with you because <reason> . But let's still <disclaimer> .
<reason>
<dubious-excuse>
<dubious-excuse> , and also because <reason>
<dubious-excuse>
my <person> doesn't like you
I'm in love with <another>
I haven't told you this before but <harsh>
I didn't have the heart to tell you this when we were going out, but <harsh>
you never <romantic-with-me> with me any more
you don't <romantic> any more
my <someone> said you were bad news
I'm working on a project in which I have to read in a Grammar file (breaking it up into my data structure), with the goal of being able to generate a random "DearJohnLetter".
My problem is that when reading in the .txt file, I don't know how find out whether the file was supposed to be a completely blank line or not, which is detrimental to the program.
Here is an example of part of the file, How do i tell if the next line was supposed to be a blank line? (btw I'm just using a buffered reader) Thanks!
<start>
I have to break up with you because <reason> . But let's still <disclaimer> .
<reason>
<dubious-excuse>
<dubious-excuse> , and also because <reason>
<dubious-excuse>
my <person> doesn't like you
I'm in love with <another>
I haven't told you this before but <harsh>
I didn't have the heart to tell you this when we were going out, but <harsh>
you never <romantic-with-me> with me any more
you don't <romantic> any more
my <someone> said you were bad news
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我理解正确的话,你只是想确定一行内下一行是否为空?
如果为真,那么这是一个启动示例:
这将打印以下内容:
If I understand you right, you just want to determine inside a line whether the next line is empty?
If true, then here's a kickoff example:
This prints the following: