I have got further into my program and am at the last hurdle, i am using String.split to split InetAddress IP using getInetAddress. so IP is storing the host name and ip address which is split by a /. I am trying to split the string using string.split but when i then try system.out or writing to a file it seems to lose the part of the string before the /. here is the code.
public void writefile(InetAddress IP) {
String [] Name;
String IPaddress = IP.toString();
Name = IPaddress.split("/");
System.out.println("The IP addres is: " + Name[1]);
System.out.println("The Hostname is: " + Name[0]);
try {
File f = new File(file);
FileWriter fw = new FileWriter(f);
BufferedWriter bw = new BufferedWriter(fw);
bw.write("The Hostname is: " + Name + "\n");
bw.flush();
bw.write("The IP address is: " + IPaddress + "\n");
bw.flush();
} catch (IOException e) {
System.err.println("File not found/created");
}
}
It is pringint the IP address fine but losing the host name, why?