Write to a file in Java module

LabKey Support Forum (Inactive)
Write to a file in Java module himanshu mendhe  2015-05-12 13:36
Status: Closed
 
Hi!
I have created a Java module and would like to write to a .doc file in the module. I would also like the same file, or a copy of it to get downloaded once it is created.
However, when I try to do the following:

OutputStream fos = new FileOutputStream(new File(this.getClass().getResource(report).toURI().toString()));

('report' is the filename)

I get a FileNotFoundException thrown by FileOutputStream. I had to add the .toString method because on the plain URI, File() was throwing a URI-Not-hierarchical exception.

When I just input a String(filename) to the File() constructor I am able to write to the file, but that file is stored on Tomcat-home.

Is there a way to initiate a download of the said file from tomcat-home? What other options do I have?
 
 
Jon (LabKey DevOps) responded:  2015-05-14 17:00