Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

reading properties file

 
Bartender
Posts: 3648
16
Mac OS X Firefox Browser 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.
 
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.
 
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".
 
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Partner, take a look here. I think it will be helpful!
 
You ought to ventilate your mind and let the cobwebs out of it. Use this cup to catch the tiny ads:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic