C:/console.dat
MESSAGE_SERVER_IP=localhost
SERVER_STATUS_PORT=4498
SERVER_CMD_PORT=4497
MAIN_REFRESH_TIMEINTERVAL=2
POOL_REFRESH_TIMEINTERVAL=2
ReadConfigFile.java
package pulse;
import java.io.*;
import java.util.*;
import java.util.StringTokenizer;
public class ReadConfigFile {
static FileReader fileReader;
static BufferedReader bd;
public static String msgServerIp = null;
public static int serverStatusPort;
public static int serverCmdPort;
public static void readConfig() throws Exception{
fileReader = new FileReader("C:/console.dat");
bd = new BufferedReader(fileReader);
String lineRead = new String();
while((lineRead = bd.readLine()) != null){
StringTokenizer stTok = new StringTokenizer(lineRead, "=");
while (stTok.hasMoreTokens()) {
String firstToken = stTok.nextToken();
System.out.println("First String Token is:" + firstToken);
if(firstToken.equals("MESSAGE_SERVER_IP")){
msgServerIp = stTok.nextToken();
System.out.println("Server IP is:" + msgServerIp);
}
else if(firstToken.equals("SERVER_STATUS_PORT")){
String ssp = stTok.nextToken();
System.out.println("Server_Status_port is:" + ssp);
serverStatusPort = Integer.parseInt(ssp);
System.out.println("Integer serverStatusPort is:" +
serverStatusPort);
}else if(firstToken.equals("SERVER_CMD_PORT"))
serverCmdPort = Integer.parseInt(stTok.nextToken());
else{
System.out.println("Second Token is:" + stTok.nextToken());
}
}
}
}
public static String getMsgServerIp() {
return msgServerIp;
}
public static int getServerCmdPort() {
return serverCmdPort;
}
public static int getServerStatusPort() {
return serverStatusPort;
}
}
>java.lang.NumberFormatException: 4498
Print out the string just prior to conversion to see what it is
seeing. Chances are there are some lead/trail spaces.
See "conversion" String -> int in the Java glossary.
The java glossary is at
http://www.mindprod.com/gloss.html
or http://209.139.205.39
--
eagerly seeking telecommuting programming work.
canadian mind products, roedy green
One fix would be to create the tokenizer with " =" (space and equals) as the
token list.
Another would be to trim() the tokens.
Steve.
>Well spotted, Roedy. Yes, there is a single space after 4498, even in the
>posted article.
I don't spot I errors, I just remember making them myself.
The java glossary is at
http://www.mindprod.com/gloss.html
or http://209.139.205.39
--
>I don't spot I errors, I just remember making them myself.
I created the file http://mindprod.com/errormessages.html
for the most part by deliberately making various errors I knew I would
make eventually and then saw what the compiler would report.
The rest are for ones I made accidentally and had to think a bit to
track them down. Some are contributions from third parties.