I have a Java class not a Java servlet
@Path("/helloworld")
public class HelloWorld {
@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();
}
}
and I want to read the file roma.txt
located in the web content as you see:
I have found many answers using getServletContext
but I am not in a servlet. Thus, I can't use that function.
Help me please to get the roma.txt
file
I am getting file not found exception
again: I swear to God that i am not on a servlet and I don't know why users just give me answers using servlet. i really appreciate it the helping, but please try to read the question first, i said in bold that I am NOT on a servlet