Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Problem with downloading files  RSS feed

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all
I am using the below given code to download files from a remote server through a web page. It works fine with files of size larger than around 10k. But it gives me an error when I try to download files below 10K. I get a pop up error message from IE saying this.
"Internet Explorer cannot download <file> from <server>"
"Internet Explorer was not able to open this Internet site. The requested site is either unavailable or cannot be found. Please try again later."
This does not happen in the case or files larger than 10k.
If any of you have any idea why this happens, help me.
Thanks in advance
--:Biju:--
java.io.File file = new java.io.File("test.txt");
java.io.FileInputStream fileIn = new java.io.FileInputStream(file);
long fileLen = file.length();
int rb = 0;
int tr = 0;
byte bArr[] = new byte[blockSize];
if(contentType == null)
response.setContentType("application/x-msdownload");
else
if(contentType.length() == 0)
response.setContentType("application/x-msdownload");
else
response.setContentType(contentType);
response.setContentLength((int)fileLen);
if(destFileName == null)
response.setHeader("Content-Disposition", "attachment;
filename=".concat(String.valueOf(getFileName("test.txt"))));
else
if(destFileName.length() == 0)
response.setHeader("Content-Disposition", "attachment;");
else
response.setHeader("Content-Disposition", "attachment;
filename=".concat(String.valueOf(destFileName)));
while((long)tr < fileLen)
{
if ((tr+blockSize) < fileLen)
{
rb = fileIn.read(bArr, 0, blockSize);
}
else
{
rb = fileIn.read(bArr, 0, (int)(fileLen-tr));
}
tr += rb;
response.getOutputStream().write(bArr, 0, rb);
}
fileIn.close();

------------------
--:Biju:--
 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hiu biju,
i want to a similar activity like u did..i.e downloading a file from a webserver and storing it in a particular directory.
how do i go about doing this in jsp where the file name is shown as a hyperlink also the file is a text file.
Another i would like to know is can i find out whether the download was sucessful or cancelled in between?
Please help me on this
Thanx in advance
Chhaya
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!