Hey,
Fik lavet lidt slamkode... der skulle virke...
import java.io.*;
import java.net.*;
public class AdressByPhoneNumber {
public static void main(String[] args) {
String phonenumber = "20320805";
URL u;
InputStream is = null;
DataInputStream dis;
String s = "";
String content = "";
String navn = "";
String gade = "";
String postnr = "";
String By = "";
try {
u = new URL("
http://www.degulesider.dk/vbw/super/resultat.do?compPhone="+phonenumber);
is = u.openStream();
dis = new DataInputStream(new BufferedInputStream(is));
while ((s = dis.readLine()) != null) {
content = content + s;
}
} catch (MalformedURLException mue) {
System.out.println("Ouch - a MalformedURLException happened.");
mue.printStackTrace();
System.exit(1);
} catch (IOException ioe) {
System.out.println("Oops- an IOException happened.");
ioe.printStackTrace();
System.exit(1);
} finally {
try {
is.close();
} catch (IOException ioe) {
}
}
int navne = content.indexOf("class=\"navn\"");
if(navne > -1){
int navne2 = content.indexOf("</td>",navne);
int adress = content.indexOf("<td style=\"width: 22px;\"></td>",navne2);
int adress2 = content.indexOf("<br>",adress);
int byen = content.indexOf(" ",adress2);
int byen2 = content.indexOf(" ",byen);
gade = content.substring(adress+52,adress2);
navn = content.substring(navne+42,navne2);
postnr = content.substring(adress2+5,adress2+9);
By = content.substring(byen+5,byen2);
System.out.println (""+navn);
System.out.println (""+gade);
System.out.println (""+postnr + " " + By);
}else{
System.out.println("Navn findes ikke");
}
}
}
Dog er dis.readLine() depricated. Hvad skal man bruge der istedet?