Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using a Configuration Setting

 
Steve Dyke
Ranch Hand
Posts: 1619
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure what Forum to put this in.

What I would like to do is have the app store a file on the client machine that would be used the next tine the app was accessed to be used to set certian filters for displayed lists. I need this to be accessed before a user logs on to the app. It would use wscript to get the user id for locating the stored file on the client.

Any help with this?
 
Henry Wong
author
Marshal
Pie
Posts: 21121
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure what Forum to put this in.


If you give us more detail, we can move it to the right forum for you.

Is this application, running on the client, a Java application? A javascript application? A C# application? etc.. It would also help if you give more details on the "wscript" that you are refering to.

Henry
 
Steve Dyke
Ranch Hand
Posts: 1619
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is a web application(JSP, Servlets, classes).

I have figured out how to pull in the entire contents of a particular file if it exists. But I am now having trouble figuring out how to find a particular line in the text file and getting the value.

Say I need the value of the DefaultDepartmentPerspective.

My text file is set up as such:

DefaultDepartmentPerspective:670
DefaultPlatformPerspective:SATC

Here is my code to read the file:

 
James Dixon
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Steve, there are a number of ways you can do this in java.

If you are, then System Properties is your friend. This will give you access to everything from the users home directory, the temporary directory and even the logged in users name. All you need to do then is pick the place you'd prefer to store your file and then create/read/update or write to it.

Here's a little program that you should be able to run that'll output all the properties your java program has access to:



 
James Dixon
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm all of a sudden a different question :-)

Looking at your code, if the format of the file doesn't change (i.e. on each line always a:b) then instead of writing to a string buffer you could write to a Map
All you would have to do then is search the string for the colon and assign what comes first as the key and after as the value. You would then be able to easily access the Map.

Another way you could achieve the same result without having to write your own string parser would be to save the file as a properties file. That way you can just reference it and call the getProperty method with the java api doing the leg work for you...
 
Steve Dyke
Ranch Hand
Posts: 1619
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
James Dixon wrote:Hmm all of a sudden a different question :-)

Another way you could achieve the same result without having to write your own string parser would be to save the file as a properties file. That way you can just reference it and call the getProperty method with the java api doing the leg work for you...


I created a properites file manually and got the app to get the desired value.

But now how do I use my app to write the properties file?

I have this so far. It creates the file but does not hold the properties:

 
Campbell Ritchie
Sheriff
Pie
Posts: 48964
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Too difficult for beginners. Off to JSP with you!
 
James Dixon
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Steve

I think you're pretty much there. If you look in the java doc for Properties you'll find a method called 'store' that'll allow you to save changes...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic