09/10/2011, 20:05
|
| | Fecha de Ingreso: octubre-2011
Mensajes: 2
Antigüedad: 13 años, 2 meses Puntos: 0 | |
Respuesta: Problema Palicacion Consola Aqui les mando mi codigo:
import java.io.*;
import java.util.*;
import java.net.*;
public class Campaing
{
static String rec;
static ArrayList number = new ArrayList();
static ArrayList rec2= new ArrayList();
public static void main(String[] args)throws Exception
{
String line;
//*************************Create URL**************************************
String link1="http://www.";
String link2=".com/";
HttpURLConnection con;
int reCode;
String reMessage;
String Message;
Campaing arch = new Campaing();
arch.LeerArchivo();
Iterator itr = number.iterator();
while (itr.hasNext())
{
String link3=link1+""+itr.next()+""+link2;
//************************ URL***********************************************
URL url = new URL(link3);
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
String s1 = connection.getRequestMethod();
StringBuffer answer = new StringBuffer();
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
con = (HttpURLConnection)url.openConnection();
reCode = con.getResponseCode();
reMessage = con.getResponseMessage();
System.out.println("HTTP response and message: " + reCode + " - " + reMessage );
while ((line = reader.readLine()) != null) //to read HTML get response
{
rec2.add(line);
//System.out.println(line);
}
System.out.println("Get the request method: " + s1);
System.out.println(connection);
System.out.println("URL built : "+ link3+"\n");
connection.disconnect();
reader.close();
Campaing ca= new Campaing();
ca.RecordFile();
}// enf of while
System.out.println("TOTAL Links Built : "+ number.size());
}
//********************************Metodo Leer Archivo************************
public void LeerArchivo()
{
try{
System.out.print("Please Enter the File Path to Load :");
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
String archivo = stdin.readLine();
BufferedReader f= new BufferedReader(new FileReader(archivo));
while((rec=f.readLine()) != null)
{
//System.out.println(number.size());
//System.out.println(rec);
number.add(rec);
//Iterator cont= number.iterator();
//System.out.println(cont.next());
}
}catch(Exception e){
System.out.println("FILE NOt FOUND: " + e);
}
}
//*************************************Record File Server Response********************
public void RecordFile()
{
try
{
FileWriter fichero = new FileWriter("ServerResponse.txt");
PrintWriter pw = new PrintWriter(fichero);
pw.println("************************");
for(int i=0; i<rec2.size();i++)
{
pw.println(rec2.get(i));
}
pw.close();
} catch (Exception e)
{
e.printStackTrace();
}
}
} |