I would like to display the contents of the url in a JTextArea. I have a url that points to an XML file, I just want to display the contents of the file in JTextArea. how can I do this?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
java.net.URL
open resource as stream (methodopenStream()
).better JComponent for Html contents would be JEditorPane/JTextPane, then majority of WebSites should be displayed correctly there, or you can create own Html contents, but today Java6 supporting Html <=Html 3.2, lots of examples on this forum or here
Assuming its HTTP URL
Open the HTTPURLConnection and read out the content
You can do that way:
Then the content of your file is stored in the
String
calledyourFileAsAString
.You can insert it in your
JTextArea
using JTextArea.insert(yourFileAsAString, pos) or append it usingJTextArea.append(yourFileAsAString)
. In this last case, you can directly append the readed text to theJTextArea
instead of using aStringBuilder
. To do so, just remove theStringBuilder
from the code above and modify thefor()
loop the following way: