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 ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

reading properties file

Posts: 3648
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
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

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 .

Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you use a "java.util.Properties" object ? You could use friendly methods such as "load", "store", "getProperty", "setProperty".
Posts: 2292
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!
    Bookmark Topic Watch Topic
  • New Topic