I have the following simple piece of code which is intended to detect that a given IPv4 address indeed only has numeric values (that is after the dots have been stripped):
import edu.gcc.processing.exceptions.net.IPAddressNumericException;
//Get the IP address
String address = "239.255.255.255";
//Check to see if this is a number
try {
String IPNumbers = address.replace(".", "");
Integer.parseInt(IPNumbers);
} catch (NumberFormatException e) {
System.out.print(e.getMessage());
}
For some reason, the NumberFormatException
is fired, and I get this error:
For input string: "239255255255"
Could someone please help me understand this? The parseInt()
method works on smaller numbers, such as 127001
.
Thank you for your time.
try using Long.parseLong(IPNumbers)