• Some users have recently had their accounts hijacked. It seems that the now defunct EVGA forums might have compromised your password there and seems many are using the same PW here. We would suggest you UPDATE YOUR PASSWORD and TURN ON 2FA for your account here to further secure it. None of the compromised accounts had 2FA turned on.
    Once you have enabled 2FA, your account will be updated soon to show a badge, letting other members know that you use 2FA to protect your account. This should be beneficial for everyone that uses FSFT.

Webfiles in JAVA(html, xml, etc.)

Aeren

n00b
Joined
Aug 29, 2005
Messages
37
Hi everyone!

I would like to know if it's possible(and how it is) to download a webpage completly with Java(like this thread you're reading now :) ) then show it in a window. I've read the big book of Java but all i found was:
URLConnection openConnection(URL)
parseURL(URL, String, int, int)
toExternalForm(URL)

Anyone knows more about this?

Thanks!

Aeren
 
Checkout the URL class

http://java.sun.com/j2se/1.5.0/docs/api/java/net/URL.html#openStream()

One way of doing it:
Code:
Url url = new Url("http://hardforum.com");
InputStreamReader in = new InputStreamReader(url.openStream());

--KK
 
KingKaeru said:
Checkout the URL class

http://java.sun.com/j2se/1.5.0/docs/api/java/net/URL.html#openStream()

One way of doing it:
Code:
Url url = new Url("http://hardforum.com");
InputStreamReader in = new InputStreamReader(url.openStream());

--KK

1. What i wanted to know if i can download it completly(including pictures for example).
2. If i have the files, how can i print it out? I thought of opening a Window/Canvas/Frame/whatever, and put it in. Is that possible, if yes, how?


Aeren
 
If swing is a possibility, look into

JEditorPane

Code:
  JEditorPane htmlPane = new JEditorPane("http://hardocp.com");
  htmlPane.setEditable(false);
  window.add(new JScrollPane(htmlPane));

--KK
 
KingKaeru said:
If swing is a possibility, look into

JEditorPane

Code:
  JEditorPane htmlPane = new JEditorPane("http://hardocp.com");
  htmlPane.setEditable(false);
  window.add(new JScrollPane(htmlPane));

--KK

Cool, that takes care of the view. But how can i download the whole page(functions doesn't interest me, but pictures would be important for showing)?
What i mean like when i'm downloading a page with IE using "save as". It saves other files as well not onlz the htm.
 
You will need to parse the html to pull out all the other references (for images you'd look for an img tag then get the src attribute).
 
But how exactly does it work? I hate to use functions if i don't know what they do.
 
Back
Top