Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Number Formatted exception

0 views
Skip to first unread message

George

unread,
Feb 11, 2002, 9:47:34 AM2/11/02
to
When I ran this ReadConfigFile.java and got the exception below.
Your help is highly appreciated.


C:\console.dat
MESSAGE_SERVER_IP=localhost
SERVER_STATUS_PORT=4498
SERVER_CMD_PORT=4497
MAIN_REFRESH_TIMEINTERVAL=2
POOL_REFRESH_TIMEINTERVAL=2

import java.io.*;
import java.util.*;
import java.util.StringTokenizer;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2002</p>
* <p>Company: </p>
* @author unascribed
* @version 1.0
*/

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")){
serverStatusPort =
Integer.parseInt((String)stTok.nextElement());
}else if(firstToken.equals("SERVER_CMD_PORT"))
serverCmdPort =
Integer.parseInt((String)stTok.nextElement());
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;
}
public static void main(String args[]){
try{
readConfig();
}catch(Exception e){
e.printStackTrace();
}
}
}
C:\JBuilder6\jdk1.3.1\bin\javaw -classpath
"C:\George\pulse\classes;C:\JBuilder6\jakarta-tomcat-3.2.3\lib\servlet.jar;C:\JBuilder6\lib\webserverglue.jar;C:\JBuilder6\jdk1.3.1\demo\jfc\Java2D\Java2Demo.jar;C:\JBuilder6\jdk1.3.1\jre\lib\i18n.jar;C:\JBuilder6\jdk1.3.1\jre\lib\jaws.jar;C:\JBuilder6\jdk1.3.1\jre\lib\rt.jar;C:\JBuilder6\jdk1.3.1\jre\lib\sunrsasign.jar;C:\JBuilder6\jdk1.3.1\lib\dt.jar;C:\JBuilder6\jdk1.3.1\lib\htmlconverter.jar;C
\JBuilder6\jdk1.3.1\lib\tools.jar;C:\acs\JdbcClasses.zip"
pulse.ReadConfigFile
java.lang.NumberFormatException: 4498
at java.lang.Integer.parseInt(Integer.java:423)
at java.lang.Integer.parseInt(Integer.java:463)
at pulse.ReadConfigFile.readConfig(ReadConfigFile.java:34)
at pulse.ReadConfigFile.main(ReadConfigFile.java:54)
First String Token is:MESSAGE_SERVER_IP
Server IP is:localhost
First String Token is:SERVER_STATUS_PORT

Gordon Beaton

unread,
Feb 11, 2002, 9:57:21 AM2/11/02
to
On 11 Feb 2002 06:47:34 -0800, George wrote:
> When I ran this ReadConfigFile.java and got the exception below.
> Your help is highly appreciated.

Are you sure that there are no spaces or other "invisible" characters
in the file? Perhaps the line in question looks like this:

"SERVER_STATUS_PORT=4498 "

If that's the case, the token "4498 " will cause that exception. Your
StringTokenizer should treat whitespace as delimiters.

/gordon

--
[ do not send me private copies of your followups ]
g o r d o n . b e a t o n @ e r i c s s o n . c o m

George

unread,
Feb 12, 2002, 9:32:24 AM2/12/02
to
n...@for.email (Gordon Beaton) wrote in message news:<a48m4h$5tr$1...@news.du.uab.ericsson.se>...

> On 11 Feb 2002 06:47:34 -0800, George wrote:
> > When I ran this ReadConfigFile.java and got the exception below.
> > Your help is highly appreciated.
>
> Are you sure that there are no spaces or other "invisible" characters
> in the file? Perhaps the line in question looks like this:
>
> "SERVER_STATUS_PORT=4498 "
>
> If that's the case, the token "4498 " will cause that exception. Your
> StringTokenizer should treat whitespace as delimiters.
>
> /gordon

Thanks Gordon,
I have solved that problem according to your solution.

0 new messages