Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Variable data in properties file?

Posted on 2007-10-09
5
Medium Priority
?
4,977 Views
Last Modified: 2008-03-25
Hello,

I'm trying to set a variable value in a Java properties file.  I want it to incorporate current datetime in the value.  Here's an example:

#Begin my.properties
a=yyyymmddhhmmss_123
#End my.properties

where 'yyyy' is the current year, 'mm' the current date, and so on.

I'm sure it's relatively simple, but I'm relatively muddleheaded today.  Thanks for your help!
0
Comment
Question by:internetcreations
  • 2
  • 2
5 Comments
 
LVL 6

Assisted Solution

by:nathana21
nathana21 earned 750 total points
ID: 20043914
e365. Reading and Writing a Properties File

    // Read properties file.
    Properties properties = new Properties();
    try {
        properties.load(new FileInputStream("filename.properties"));
    } catch (IOException e) {
    }
   
    // Write properties file.
    try {
        properties.store(new FileOutputStream("filename.properties"), null);
    } catch (IOException e) {
    }


0
 
LVL 86

Accepted Solution

by:
CEHJ earned 750 total points
ID: 20043952
props.setProperty("a", String.format("%tY%<tm%<td%<tH%<tM%<tS_123", new Date()));
0
 
LVL 6

Assisted Solution

by:nathana21
nathana21 earned 750 total points
ID: 20043980
after the Properties declaration this >> 

DateTime cDate = new DateTime(2007, 3,4);
props.setProperty("a", "cDate");
0
 
LVL 92

Expert Comment

by:objects
ID: 20045125
Use the following to format your entries, and the code postyed by nathana21 to read/updatye and write your Properties.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 21205313
:-)
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question