0

I create a web service using JAVA. I want to create a log file in the server to recover it later but my problem is that I cannot save the file due to client rights. In my local server, I can save it in the root path, but in the Devian server where I will use it, this is not possible. I try to change the path, but the problem remains because my local paths are different than other server. This is my code:

BufferedWriter bw = null;
            FileWriter fw = null;
            try {           
            File file = new File(System.getProperty("user.dir")+File.separator+"zlm_"+thoy+".txt");
                // Si el archivo no existe, se crea!
                if (!file.exists()) {
                    file.createNewFile();
                }
                // flag true, indica adjuntar información al archivo.
                fw = new FileWriter(file.getAbsoluteFile(), true);
                bw = new BufferedWriter(fw);
                bw.write(entrada+";"+porcentaje+";");               
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                try {
                                //Cierra instancias de FileWriter y BufferedWriter
                    if (bw != null)
                        bw.close();
                    if (fw != null)
                        fw.close();
                } catch (IOException ex) 
{
                    ex.printStackTrace();
                }
            }

Any ideas?

sotix
  • 822
  • 1
  • 8
  • 23

2 Answers2

1

I recommend putting it in /var/log or in the /tmp directory. If you still don't have permissions to those directories, you can always put it in the relative/working directory of the war file.

More on how to create files in the working directory in this answer.

1

Make the path to the log file configurable so the server admin can set it. Ask the admin for a path to test it on.

sotix
  • 822
  • 1
  • 8
  • 23