//Web client in socket programming
import java.net.*;
import java.io.*;
public class WebClient
{
public static void main(String[] args)throws Exception
{
//open a socket to the URL www.java2s.com"
InetAddress IPobject=InetAddress.getByName("www.java2s.com");
Socket Fromclient= new Socket(IPobject,80);
PrintWriter OutToServer= new PrintWriter(Fromclient.getOutputStream());
OutToServer.println("GET / HTTP/1.1");
OutToServer.println("Host: www.java2s.com");
OutToServer.println("");//send a blank line
OutToServer.flush();//do not forget
BufferedReader FromServer=new BufferedReader(new InputStreamReader(Fromclient.getInputStream()));
String InfoFromServer;
File outputFile= new File("C:\\Users\\test\\Desktop\\Output1.txt");
FileOutputStream FileOutobj= new FileOutputStream(outputFile);
PrintWriter ToFile= new PrintWriter(FileOutobj);
while( (InfoFromServer= FromServer.readLine())!=null)
{
System.out.println(InfoFromServer);
ToFile.println(InfoFromServer);
}
ToFile.flush();
ToFile.close();
}//end of main
}//end of class