*
The moose likes Servlets and the fly likes Saving HTML page as a file on hard disc. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Saving HTML page as a file on hard disc." Watch "Saving HTML page as a file on hard disc." New topic
Author

Saving HTML page as a file on hard disc.

Anand Kaimal
Greenhorn

Joined: Sep 27, 2000
Posts: 21
Hi Java Ranchers; is there a way to directly save an html page of a site using a servlet and save it directly on to the hard disc without opening a browser?
Thanks in advance,
Anand.


Anand
Sandeep Jain
Ranch Hand

Joined: Oct 25, 2000
Posts: 124
Hi ,
I dont know whether ur requirement was the same or not but what I could undestand can be achieved through this .
Make use of URL Class in an application , get all the data and store it in buffer and later on write it to the file .
------------------
Sandeep Jain


Try and Try Till u succeed<br /> <br />Sandeep Jain
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
You do it in a servlet the same way you do in any other Java class. Open a URLConnection to the desired URL and read from the provided inputStream. Then to save to disk, just write the contents of the stream out to a FileOutputStream.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Anand Kaimal
Greenhorn

Joined: Sep 27, 2000
Posts: 21
Thanks guys,
I will try to do that.
Anand.
Anand Kaimal
Greenhorn

Joined: Sep 27, 2000
Posts: 21
I tried it and it works. Here is the code.
import java.net.*;
import java.io.*;
public class savefile
{
public static void main(String args[])
{
try
{
URL tempUrl = new URL("http://www.hotmail.com/");
InputStream inStr = tempUrl.openConnection().getInputStream();
BufferedInputStream bins = new BufferedInputStream(inStr);
FileOutputStream fostreame = new FileOutputStream("out.html");
int c;
while((c= bins.read())!=-1)
{
fostreame.write(c);
}
fostreame.close();
bins.close();
inStr.close();

}
catch (Exception e)
{
e.printStackTrace();
}


}
}
Thanks guys,
Anand.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Saving HTML page as a file on hard disc.
 
Similar Threads
URGENT :- Hide folder / file using Java
Rediff.com offers one GB e-mail space
how to make editable page non editable when i press save?????
How can I save processed Image from Applet
How to persist the JSP produced output to a file without using the browser i.e I want