Krick wrote:
> Is it ok for me to have a FileInputStream and a FileOutputStream open
> on the same file at the same time? Should I be closing and reopening
> the file or is something happening behind the scenes that I'm not
> aware of? Here's my sample code which seems to work ok:
>
>
> String property;
>
> File f = new File("my.properties");
> Properties p = new Properties();
>
> // load the properties from the file
> try {
> p.load(new FileInputStream(f));
> }
> catch (IOException ex) {
> }
>
> // get the property
> property = p.getProperty("foo");
>
> // do stuff here, possibly modifying property
>
> // set the property
> p.setProperty("foo", property);
>
> // store the properties to the file
> try {
> p.store(new FileOutputStream(f), "MY PROPERTIES");
> }
> catch (IOException ex) {
> }
I think that's unwise, but I can't predict what will happen. Actually,
I think that's unwise BECAUSE I can't predict what will happen. I in
general think that this kind thing is unwise; the FileInputStream and
FileOutputStream you use will be closed when they are GCd, but you can't
predict when that will be. In the mean time they consume OS resources
that are likely to be considerably more precious than memory, and there
is moreover a potential for them to conflict. The minor programming
convenience is just not worth it.
John Bollinger