在Java中逐行读取字符串(Read String line by line)_电脑培训

给定一个不太长的字符串,逐行阅读的最好方法是什么?

我知道你可以做:

BufferedReader reader = new BufferedReader(new StringReader(<string>));
reader.readLine();

另一种方式是将子串置于eol上:

final String eol = System.getProperty("line.separator");
output = output.substring(output.indexOf(eol + 1));

任何其他可能更简单的做法吗? 我没有上述方法的问题,只是有兴趣知道,如果有人知道可能看起来更简单和更有效率的东西?

Given a string that isn't too long, what is the best way to read it line by line?

I know you can do:

BufferedReader reader = new BufferedReader(new StringReader(<string>));
reader.readLine();

Another way would be to take the substring on the eol:

final String eol = System.getProperty("line.separator");
output = output.substring(output.indexOf(eol + 1));

Any other maybe simpler ways of doing it? I have no problems with the above approaches, just interested to know if any of you know something that may look simpler and more efficient?

原文:https://stackoverflow.com/questions/1096621


原网址: 访问
创建于: 2021-06-17 14:32:59
目录: default
标签: 无

请先后发表评论
  • 最新评论
  • 总共0条评论