Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

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

 
Greenhorn
Posts: 13
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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;

try{

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


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


//set response headers
response.setContentType("text/plain");

response.addHeader(
"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)
myOut.write(readBytes);

} catch (IOException ioe){

throw new ServletException(ioe.getMessage( ));

} finally {

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

}



%>
 
Get off me! Here, read this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic