JBoss EAP 6.3.0 Application saves file in working folder

I am writing an application that will run inside JBoss EAP 6.3.1 on CentOS 6.5

During this application, I have to save the file to disk, and when I restart the application, I have to read it in the application.

It all works.

The problem is, I want to save the file in the application working directory.

What is happening now is that the file: foo.bar will be saved in the location where I run standalone.sh (or .bat on Windows).

public void saveToFile() throws IOException {
    String foo = "bar";

    Writer out = new OutputStreamWriter(new FileOutputStream("/foo.bar"), "UTF-8");
    try {
        out.write(foo);
    } finally {
        out.close();
    }
}

      

+3


source to share


1 answer


You can try to use an absolute path to save the file:

String yourSystemPath = System.getProperty("jboss.home.url") /*OPTIONAL*/ + "/want/to/save/here";
File fileToSave = new File(yourSystemPath,"foo.bar");  
Writer out = new OutputStreamWriter(new FileOutputStream(fileToSave), "UTF-8");

      



Basically here I am creating an object File

using a variable yourSystemPath

where I saved the path to save the file and then create new FileOutputStream(fileToSave)

using the previously created objectFile

Make sure your JBoss server has write permissions for yourSystemPath

+2


source







All Articles