0

I have a webapp in Java SEAM2 running on JBOSS.

In my application I am trying to create directories on the fly / runtime.

Well what happens is that these directories get created, but when I try to write a file into them it throws a null pointer exception. So restarted my server and all works well then, why is it ?

if(ClassName.class.getClassLoader().getResource("roles/" + role ) == null)
        {
            //create directory with role name
            String rolePath = ClassName.class.getClassLoader().getResource("roles").getPath();
            rolePath = rolePath.substring(1, rolePath.length());
            rolePath = rolePath.replace("/", "\\");
            rolePath = rolePath + "\\" + role;

            if( !(new File(rolePath).mkdir()))
            {
                this.addMessage(FacesMessage.SEVERITY_ERROR, "Error Creating Role Directory");
                return;
            }

        }



        if(ClassName.class.getClassLoader().getResource("roles/" + role + "/" + app ) == null)
        {
            String appPath = ClassName.class.getClassLoader().getResource("roles/" + role).getPath();
            appPath = appPath.substring(1, appPath.length());
            appPath = appPath.replace("/", "\\");
            appPath = appPath + "\\" + app;

            File appFolder = new File(appPath);
            if( !(appFolder.mkdir()))
            {
                this.addMessage(FacesMessage.SEVERITY_ERROR, "Error Creating Role Directory");
                return;
            }


        }

My guess is that since I am using getClassLoader it is not getting updated with the new files created

1
  • Maybe you should post relevant code snippet. Commented Oct 18, 2010 at 5:53

1 Answer 1

1

It is a bad idea to create a folder base a resource path from class loader (you never where is the srouce/folder from) better way are, use java.io.temp folder, or use a configuration to know get repository folder in your system.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.