• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

reading properties file

 
K. Tsang
Bartender
Posts: 3583
16
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all, I have a rather stupid question to ask: How to read the properties file as plain text?

I use RandomAccessFile to read and update (if users want to change it). My file looks like this:

local dir data
local file db-1x1.db
server address 127.0.0.1
server port 1099
server dir data
server file db-1x1.db


I use while loop to check if raf.readLine() contains "local" or "server" and assign the corresponding variables to the File constructor.
Now my problem is the position of these lines. If I put the "local" lines first and run the stand-alone version, everything goes well. Now without changing the file or code, I run the network version, I get "null" for the file. If i include lines 2-6 in the code, running the network version I get NullPointerException on the 2nd while line (line 7).



Similarly if I put the server lines first then the local lines in the properties file, and run the standalone version, I get null. When lines 2-6 included, I get NullPointerException.

Can someone please help why I get NullPointerException when lines2-6 code are included? This set of code hopes to cater I don't have to start reading on line 1 (position 0) of the file.
 
mohamed sulibi
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi;

i just want to ask you that your post about what ?
i don't understand if you ask for a specific idea in scjd or in general way .

regards.
 
christian combarel
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Why don't you use a "java.util.Properties" object ? You could use friendly methods such as "load", "store", "getProperty", "setProperty".
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Partner, take a look here. I think it will be helpful!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic