Results 1 to 3 of 3
  1. #1
    hotsauce1183 is offline Member
    Join Date
    Feb 2011
    Posts
    5
    Rep Power
    0

    Default Clear InputStream Cache

    I know this has got to be a common problem but so far I havent found any references to this issue:

    I have a small method thats supposed to open a parameter file as an inputStream, read the contents into a Parameter array and then close the stream; but after the first open/read/close sequence it seems to be caching the information because even if I delete the file the method still returns its previous contents.

    Java Code:
        public  Map<String, String> extractAndLoadConfigurationFile()  throws IOException, FileNotFoundException
        {
            String fFinalFile = ("PromoteMatches.properties");
            InputStream is=null;
            Map<String, String> fMergedProps=new HashMap<String,String>();
            
            is = getClass().getClassLoader().getResourceAsStream(fFinalFile);
            log.debug("property file loaded through standard getClass.getClassloader: " + (is != null));
    
            if (is != null)
            {
                Properties p = new Properties();
                try
                {
                    p.load(is);
                    is.close();
                    for (Iterator< ? > iterator = p.keySet().iterator(); iterator.hasNext();)
         ...

    So how do you terminate this caching action on an input stream?

  2. #2
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    I think the issue is that the classloader caches resources. I can't think of any way to cause it to reload a resource.

    The idea behind class resources is that they are static, so what you are trying to do is probably unsupported in any way. You would probably be better served to load the file using a FileInputStream.

  3. #3
    hotsauce1183 is offline Member
    Join Date
    Feb 2011
    Posts
    5
    Rep Power
    0

    Default

    Thanks Toadaly - I did think of switching input methods but wasnt sure which other one to choose. I am fairly new to Java and your lead helps a lot.

    Cheers,

    Roger

Similar Threads

  1. Creating an InputStream
    By c26354 in forum New To Java
    Replies: 10
    Last Post: 07-12-2011, 04:48 AM
  2. InputStream problem
    By javabarn in forum New To Java
    Replies: 10
    Last Post: 06-29-2010, 04:09 PM
  3. How to clear cache of an Applet/JApplet
    By tanmoy.b81 in forum AWT / Swing
    Replies: 0
    Last Post: 08-11-2008, 11:54 AM
  4. clear cache
    By Jadellll in forum New To Java
    Replies: 0
    Last Post: 03-20-2008, 09:27 AM
  5. JSP - using connection cache
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-30-2008, 09:54 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •