+ 3

Question regarding property files

I am new to java and I wrote a class that creates a property file. But when i read it i also get a timestamp. Where does this timestamp come from? Here the code for reference import java.io.*; import java.util.*; public class WritePropertiesFile { public static void main(String[] args){ try{ Properties properties = new Properties(); properties.setProperty("username", "abcdef"); properties.setProperty("password", "012345"); File file = new File("c://........"); if(file.createNewFile()){ System.out.println("File is created!"); } else{ System.out.println("File already exists"); } FileOutputStream fileOut = new FileOutputStream(file); properties.store(fileOut, "User"); fileOut.close(); } catch(FileNotFoundException e){ e.printStackTrace(); } catch(IOException e){ e.printStackTrace(); } } } Output: #User #Thu Mar 09 14:06:25 CET 2017 password=012345 username=abcdef

9th Mar 2017, 1:14 PM
Naschkatzification
Naschkatzification - avatar
1 Antwort
0
By output you mean the content of the output file? By the way, it seems clear that the Properties class have a method which uses the given OutputStream to write its data into it. That method contains the format of the file output generating, so in a nutshell, Properties does save itself into file this way. May you could check if there is a flag on the object like .setUseTimestamp(false) or there is an overload of thr method which accepts a boolean parameter for that. Anyways, Properties structure is like any config file, tags and values, this plus information does not influence the stored data, that's like a comment. Reason? Why not. Sometimes it can be useful to check who was the last modifier.
10th Mar 2017, 4:06 PM
Magyar Dávid
Magyar Dávid - avatar