File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Using a Configuration Setting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Using a Configuration Setting" Watch "Using a Configuration Setting" New topic
Author

Using a Configuration Setting

Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1391
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
Sheriff

Joined: Sep 28, 2004
Posts: 18117
    
  39

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1391
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

Joined: Jun 20, 2009
Posts: 32
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

Joined: Jun 20, 2009
Posts: 32
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

Joined: Nov 16, 2004
Posts: 1391
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

Joined: Oct 13, 2005
Posts: 36486
    
  16
Too difficult for beginners. Off to JSP with you!
James Dixon
Ranch Hand

Joined: Jun 20, 2009
Posts: 32
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...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using a Configuration Setting
 
Similar Threads
URL-Rewriting, Bullet Proof way?
URL Re-writing, Bullet Proof Way?
To Michael Yuan Need Help
Java network client application, is it possible??
Dynamically Creating Variables