i am on a java class, i am not on a servlet
the question is not duplicated, i am not on a servlet please guys.
and by a java class, i mean:
class HelloWorld{}
I am on server, and I want to allow the client to download a file
this is my code:
@GET
@Produces(MediaType.APPLICATION_OCTET_STREAM)
@Path("/downloadFile")
public Response getFile() {
File file = new File("/roma.txt");
System.out.println("path = " + file.getPath());
System.out.println("absoulte path = " + file.getAbsolutePath());
return Response
.ok(file, MediaType.APPLICATION_OCTET_STREAM)
.header("Content-Disposition",
"attachment; filename=\"" + file.getName() + "\"") // optional
.build();
}
the file is located in the WebContent
of my project as you see here:
i got this exception:
java.io.FileNotFoundException: /roma.txt (No such file or directory)