• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Re: Attach is the detail on the servlet error "The system cannot find the path specified"

minhdung tran
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good morning, I have a very simple program which downloads a text file from my server c drive c:\mydir\test.txt to a user's computer specific drive. However, the program constantly giving me error telling me that "The system cannot find the path specified". I don't know what is going wrong in the program and why the servlet could not find the specific file test.txt in my c drive c:\mydir\test.txt. Attach is my program for you to review.
<%@ page import="java.io.FileInputStream" %>
<%@ page import="java.io.BufferedInputStream" %>
<%@ page import="java.io.File" %>
<%@ page import="java.io.IOException" %>


// you can get your base and parent from the database
String filename="test.txt";

String filepathServer = "c:\\mydir\\";

BufferedInputStream buf=null;
ServletOutputStream myOut=null;


myOut = response.getOutputStream( );
File myfile = new File(filepathServer+filename);

out.println ("Server file " + myfile + "\n");

//set response headers

"Content-Disposition","attachment; filename="+ filename );

response.setContentLength( (int) myfile.length( ) );

FileInputStream input = new FileInputStream(myfile);
buf = new BufferedInputStream(input);
int readBytes = 0;

//read from the file; write to the ServletOutputStream
while((readBytes = buf.read( )) != -1)

} catch (IOException ioe){

throw new ServletException(ioe.getMessage( ));

} finally {

//close the input/output streams
if (myOut != null)
myOut.close( );
if (buf != null)
buf.close( );


  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic