Code: JSP
File inputFile = new File("C:\\test.java"); // put your filename here
   
BufferedReader br = new BufferedReader(new FileReader(inputFile));
   
System.out.println(br.readLine());
System.out.println(br.readLine());

response.setContentType("application/octect-stream");
response.setHeader("Content-Disposition","attachment; filename=" + "yourfile.txt" );