I have a temporary file with data that's returned as part of a SOAP response via a MTOM binary attachment. I would like to trash it as soon as the method call "ends" (i.e., finishes transferring). What's the best way for me to do this? The best way I can figure out how to do this is to delete them when the session is destroyed, but I'm not sure if there's a more 'immediate' way to do this.
FYI, I'm NOT using Axis, I'm using jax-ws, if that matters.
UPDATE: I'm not sure the answerers are really understanding the issue. I know how to delete a file in java. My problem is this:
@javax.jws.WebService
public class MyWebService {
...
@javax.jws.WebMethod
public MyFileResult getSomeObject() {
File mytempfile = new File("tempfile.txt");
MyFileResult result = new MyFileResult();
result.setFile(mytempfile); // sets mytempfile as MTOM attachment
// mytempfile.delete() iS WRONG
// can't delete mytempfile because it hasn't been returned to the web service client
// yet. So how do I remove it?
return result;
}
}