dcsimg
Show the prefetched images with HTML code in JEditorPane
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Fung_Sandra
Posted On:   Sunday, April 1, 2001 09:04 PM

I get all HTML code from web and save in my local computer. That is successful to find the file in my computer. The code is following : URL u = new URL("http://java.sun.com"); InputStream in = u.openStream(); while((input=in.readLine())!=null){ text3+=" "+input; } FileOutputStream out=new DataOutputStream(new FileOutputStream("c:/prefetching"+"/temp"+".html")); out.writeBytes(text3); out.close(); At the same time, the images of the web page has been fetched as well and save in the corresponding location in my computer. I want to open them and display this page in JEditorPane. The code is the following: JEditorPane pane=new JEditorPane(); f   More>>

I get all HTML code from web and save in my local computer. That is successful to find the file in my computer. The code is following :
URL u = new URL("http://java.sun.com");
InputStream in = u.openStream();
while((input=in.readLine())!=null){ text3+="
"+input; }
FileOutputStream out=new DataOutputStream(new FileOutputStream("c:/prefetching"+"/temp"+".html"));
out.writeBytes(text3);
out.close();

At the same time, the images of the web page has been fetched as well and save in the corresponding location in my computer. I want to open them and display this page in JEditorPane. The code is the following:
JEditorPane pane=new JEditorPane(); filepath="c:/prefetching"+"/temp"+".html"; DataInputstream in = new DataInputStream(new FileInputStream(filepath)); while ((text=in.readLine())!=null){ text2+="
"+text; } in.close(); if(text2!=""){ pane.setContentType("text/html"); pane.setText(text4); }
It can show the page in JEditorPane except the images, how can I do to display the images?

   <<Less

Re: Show the prefetched images with HTML code in JEditorPane

Posted By:   Tim_Rohaly  
Posted On:   Thursday, April 19, 2001 05:29 PM

A component which displays
HTML (e.g. JEditorPane or a web browser) reads each
tag in turn from the HTML file
and renders it appropriately. In the case of images,
the component is reading the tag, which contains
a URL for the image to render. Most pages specify
these URLs as relative URLs, but some use absolute
or fully qualified URLs. If you want to write all the
HTML files and images to your local disk and have it
load from there, you must rewrite all the tags
to make sure they point to the images files on your
local disk. It may be easier to try this out by hand-editing
a few of the downloaded pages at first then attempting
to view the HTML page in a web browser - it will be clear
when you have done it properly.
About | Sitemap | Contact