I am developing a project in that i have a module in which i need to write a Java Program to read a html page and save its HTML code of the page in a text file. Please can anyone give that above said program .......
2 Answers
have a look at http://docs.oracle.com/javase/tutorial/networking/urls/readingURL.html you dont even need an external library. Combine this with a Bufferedwriter:
import java.net.*;
import java.io.*;
import java.util.*;
public class URLReader {
public static void main(String[] args) throws Exception {
URL oracle = new URL("http://www.oracle.com/");
BufferedReader in = new BufferedReader(
new InputStreamReader(oracle.openStream()));
BufferedWriter writer = new BufferedWriter(new FileWriter("outputfile.txt"));
String inputLine;
while ((inputLine = in.readLine()) != null){
try{
writer.write(inputLine);
}
catch(IOException e){
e.printStackTrace();
return;
}
}
in.close();
writer.close();
}
}