File Path (Java Web)

0

I'm working on a web project and I'm having a problem with files ( java.io.File ). The problem is only when I am running the web application, if it is Java Application the problem does not exist.

When instantiating a file, new File("diretorio"); , its path becomes C://Windows/System32/diretorio , so I can not do anything, maybe because I do not have Windows privileges.

"I solved the problem" by passing new File("C://Users/myName/diretorio") , but I did not like the solution, I wanted to do automatic, to get the path of the application itself, for example, since I am developing on my machine and after deploy, . do not know.

Any tips?

Follow the part of the project that I'm having the problem with, a jsf bean. My view calls the addFile() method in order to save the file I receive from the view. It's all functional, but I have to pass the path as I said earlier, as it is in the code below, the path goes to the Windows System32 folder.

Bean.java

@ManagedBean
@ViewScoped
public class Bean {

    //ATRIBUTOS E LÓGICAS DE NEGÓCIO

    public void addFile() {

        File temporario = new File("temporario");
        //LÓGICA DE NEGÓCIO

    }
}
    
asked by anonymous 29.06.2017 / 20:51

1 answer

0

This solves the problem. File myTempFile = new File(System.getProperty("java.io.tmpdir"),"temporary"); It serves exactly for a temporary file.

    
30.06.2017 / 07:13