I am trying to write a config file in Java, and I put my port number in it so that the HTTP HTTP server can connect to the root path as well as the root path.
Configures the file:
root= some root port=8020
I am trying to access the following properties:
FileInputStream file = new FileInputStream("config.txt"); //loading properties from properties file config.load(file); int port = Integer.parseInt(config.getProperty("port")); System.out.println("this is port " + port);
If I do this with a single parameter in the getProperty method, I get this error
"java.lang.NumberFormatException: null"
However, if I refer to it like this:
int port = Integer.parseInt(config.getProperty("port", "80"));
it works.
In addition, it works for config.getProperty("root"); so i don't understand ...
Edit:
import java.net.*; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.util.*; public class Server { public static void main(String[] args) throws Exception { boolean listening = true; ServerSocket server = null; Properties config = new Properties(); int port = 0; try {
source share