Search code examples
javaweb-servicesrestprintwriter

PrintWriter not working java web service


I have a java project with threads which writes info in a log file. What i was doing was the following:

create the file when creating a Process( PrintWriter file its an attribute):

public Process(int id){
        id_proc= id;
        try {
            file=new PrintWriter("log_acuerdo_" + this.id_proc +".txt");
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

Then, when i wanted to write something in it:

file.println("P0" + msj.emisor + " " + msj.id);

Then, after all threads were done writing i did this:

for(int i=0; i<cant_proc; i++)
    ((Process)procesos[i]).file.close();

This was working perfectly fine. Then, i wanted to change the project and use REST instead, i mean, web services. The whole project is working ok, except it's not creating any file or nothing is being written.

Any idea why?


Solution

  • If you're using REST, then your files are being created inside your eclipse folder. Take a look there. There are a bunch of other folders like 'p2', 'configuration', 'readme' and other stuff.