• Post Reply Bookmark Topic Watch Topic
  • New Topic

Reading value from file and passing it as a parameter  RSS feed

 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have a plain text file carrying name value pairs ( some 10+ in count) and I have to pass the all the values as a parameters to one of the methods in Java.
What is the best way to read and pass the value to the method.

Please suggest.

Thanks,
Faraz
 
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your best bet is to use Properties to load, manipulate, and pass the data around.
 
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Passing values to a method is completely independent from reading values from a file. Don't confuse and intermingle them.
 
Ranch Hand
Posts: 143
Android Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my opinion i will use .ini files to store paired values

read this http://ini4j.sourceforge.net/apidocs/overview-summary.html

-Supun
 
Ranch Hand
Posts: 499
AngularJS Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Supun Lakshan Dissanayake,


Just a doubt. Why use ini files can't we use arrays to store the values and pass it as parameters?
 
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Partheban Udayakumar wrote: . . . can't we use arrays to store the values and pass it as parameters?
Parallel arrays sound like poor design to me.
 
Supun Lakshan Dissanayake
Ranch Hand
Posts: 143
Android Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Partheban Udayakumar wrote:Supun Lakshan Dissanayake,


Just a doubt. Why use ini files can't we use arrays to store the values and pass it as parameters?


Yeah we can use arrays too.

I suggest op to use ini files to store paired values. not to pass them.

to pass them i think varargs is the best
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Supun Lakshan Dissanayake wrote: . . . to pass them i think varargs is the best
Varargs for paired values? That does not sound a good idea at all. If you have values which are paired, they are probably best wrapped into an object and that object (or more precisely its reference) passed.
 
Supun Lakshan Dissanayake
Ranch Hand
Posts: 143
Android Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Varargs for paired values? That does not sound a good idea at all. If you have values which are paired, they are probably best wrapped into an object and that object (or more precisely its reference) passed.


varargs for parameters.

ini files for store and get paired values.
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Supun Lakshan Dissanayake wrote: . . . varargs for parameters. . . .
That still sounds like nonsense to me. Please justify yourself.
 
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had never heard of the ini files before this and after following the link that you posted to the ini4j project I still don't understand what it is or why it's needed in this case. IMO, Steve's reply to this thread is the most logical approach for the use case at hand.
 
Partheban Udayakumar
Ranch Hand
Posts: 499
AngularJS Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with Campbell Ritchie, why do you want varargs, if you want a dynamic array you can always use Collections as Array List etc...
 
Supun Lakshan Dissanayake
Ranch Hand
Posts: 143
Android Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here is how i understood this problem

A text file has list of properties with associated values and properties count is NOT a constant
we can use ini files to store property and value.
ex:
[configuration]
remoteIP = localhost
version = 1.0


if OP pass arguments to

So OP can use method as following


 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Still looks like something for a properties object, as Steve Luke suggested a long time ago.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!