• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

reading properties file

 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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".
 
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Partner, take a look here. I think it will be helpful!
 
If you two don't stop this rough-housing somebody is going to end up crying. Sit down and read this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic