unload a properties file


hi there

i'm using this

Properties properties = new Properties();

properties.load (.......)

to load a properties file

Can someone tell me how i unload or close the properties file

many thanks
daleconAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
WebstormConnect With a Mentor Commented:

File f = new File("path to properties file");
FileInputStream fis = new FileInputStream(f);
try
{
    properties.load(fis);
    .......
}finally{
    fis.close();
}
0
 
objectsCommented:
the load method closes it for you once read.
you don't need to do anything
0
 
CEHJCommented:
You don't. It's closed automatically
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
daleconAuthor Commented:


ok thanks
0
 
WebstormCommented:
>> Can someone tell me how i unload or close the properties file
If you mean unloading from memory, you can do :
    properties = new Properties();
old instance reference is lost and will be garbage-collected.
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Or you can simply assign it to null:

properties = null ;
0
 
daleconAuthor Commented:


I'm seeing this in our tomcat logs, we were doing load testing, never seen this before

Properties exception java.io.FileNotFoundException: ... path to properties file ... (Too many open files)
WebappClassLoader: Failed to open JAR
0
 
objectsCommented:
Doubt it caused by Propoerties class, more likely to be elsewhere in your application.
0
 
CEHJCommented:
>>(Too many open files)

Don't think that means that a properties file got left open ;-) It could in fact mean that you've too many *sockets* open
0
 
WebstormCommented:
>> Properties exception java.io.FileNotFoundException: ... path to properties file ... (Too many open files)
There may be some InputStream/OutputStream you haven't closed in your application.

You should use streams like that:

     FileInputStream fis=new FileInputStream(" ... "); // or other opening of stream
     try{
          ... read/write
     } finally {  fis.close(); }
0
 
daleconAuthor Commented:


i do this

Properties properties = new Properties();

try
{
    properties.load(new FileInputStream(new File("path to properties file")));
    .......
}
catch
.......
0
 
mrigankConnect With a Mentor Commented:
try
{
    File f = new File("path to properties file");
    FileInputStream fis = new FileInputStream(f);
    properties.load(fis);
    .......
    fis.cose();
    f.close();
}
0
 
daleconAuthor Commented:


try
{
    File f = new File("path to properties file");
    FileInputStream fis = new FileInputStream(f);
    properties.load(fis);
    .......
    fis.cose();
    f.close();
}

yep that's what i've changed it to, hopefully now when we do our load testing it won't be my code throwing the errors :]
0
 
WebstormCommented:
try my suggestion
0
 
Mayank SAssociate Director - Product EngineeringCommented:
>> that's what i've changed it to

You should close in the finally blocks like Webstorm told you.
0
All Courses

From novice to tech pro — start learning today.