逐行读取 JTextPane
有没有办法逐行读取 JTextPane
的内容?很像 BufferedReader 吗?
Is there a way to read the contents of a JTextPane
line by line? Much like the BufferedReader?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
获得根元素后,您可以检查存在多少个子元素(即行)。然后,您可以获取每个子元素并使用开始/结束偏移方法来获取该特定行的文本。
这比将所有文本放入一个大字符串中然后再次拆分它更有效。
Once you get the root Element you can check to see how many child elements (ie. lines) exist. Then you can get each child Element and use the start/end offset methods to get the text for that particular line.
This would be more efficient than getting all the text in one big string and then splitting it again.
我过去执行此操作的方法是在窗格上使用 getText 方法,然后解析返回的字符串以查找换行符“\n”。
The way that I've done this in the past is to use the getText method over my pane, then parse the string that is returned looking for the newline character '\n'.
你能解释一下你想做什么吗?从头到尾,我不能说是否可以实际逐行阅读它。当然,您可以仅按换行符拆分文本,然后您将获得一个字符串数组,每一行作为其自己的元素。这对你来说是一个问题吗?
Can you explain what you're trying to do? From the top of the head I can't say if it is possible actually to read it line by line. Of course you could just split the text by the newline character and then you would get an array of strings, each line as its own element. Is this a problem in your case?