I have a Java program "PropertyWrite" to write a property file "crazy.properties" into the directory C:Windows
import java.io.*;
import java.util.Properties;
public class PropertyWrite {
public static void main(String[] args) throws Exception {
File myprop = new File("C:\WINDOWS\crazy.properties");
Properties props = new Properties();
props.setProperty("testprop", "crazy");
OutputStream os = new FileOutputStream(myprop);
props.store(os, "comment");
os.close();
System.out.println(myprop.exists()); // returns true
}
}
When i search for that file via Windows File Explorer, it is not visible
Also "Cmd -> dir" does not show the file
Somehow the file seems to be hidden
If i try to read the file with my program "PropertyRead"
it works fine and it prints the value "crazy" as expected
import java.io.*;
import java.util.Properties;
public class PropertyRead {
public static void main(String[] args) throws Exception {
File myprop = new File("C:\WINDOWS\crazy.properties");
System.out.println(myprop.exists()); // returns true
Properties props = new Properties();
FileInputStream in = new FileInputStream(myprop);
props.load(in);
in.close();
System.out.println(props.getProperty("testprop")); // prints crazy
}
}
And now it's going crazy:
If i manually create the same file (crazy.properties with content -> testprop=handmade)
and move it to the folder C:Windows the Explorer is able to show the file.
The file seems visible
Now i restart "PropertyRead" -> it prints NOT "handmade" -> it prints "crazy"
What the hell???
Now i delete the file "C:WINDOWScrazy.properties" via Explorer and restart
PropertyRead
the file is still there (but invisible) and it prints "crazy"
How can that be?
thanks in advance
question from:
https://stackoverflow.com/questions/65834889/why-are-java-property-files-not-visible-in-c-windows 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…