SCRIVETE UN PROGRAMMA CHE LEGGE UNA LISTA DI URL DA UN FILE ASCII E CONTROLLA SE SONO ONLINE DANDO,IN CASO DI PROBLEMI, UN MESSAGGIO DI ERRORE

Click to rate this post!
[Total: 0 Average: 0]

file CheckURL.java


Questo programma va fatto girare con :

java -Dsun.net.client.defaultReadTimeout=60000 
-Dsun.net.client.defaultConnectTimeout=60000 CheckURL

—–

import java.net.*;
import java.io.*;

class CheckURL {
  static BufferedReader myInput;
  static  FileReader myFile;
  public static void main (String[] args) {
      try{
         String nomeurl;
         myFile = new  FileReader('list.txt');
         myInput = new BufferedReader(myFile);
         while ( myInput.ready() ){
             nomeurl=myInput.readLine();
             try {
                URL theURL = new URL (nomeurl);
                System.out.println('Testing '+nomeurl);
                try {
                  URLConnection con=  theURL.openConnection();
                  con.getContent();
                  String temp=con.getHeaderField(0);
                  System.out.println('Header '+temp);
                  int fileNotFound=temp.indexOf('Not Found');
                  if ( fileNotFound >=0 )          
                     System.out.println('***********Bad link***************');
                  }catch(IOException e){
                     System.out.println('***********Bad link***************'); 
                  }
                } catch (MalformedURLException e) {
                  System.out.println('Malformed URL Exception '+e);             
                }
               }
            }catch(Exception e2){}
       }
   }

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x