• 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:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Unable to download small sized PDF files properly

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All
I'm trying to download a pdf files from FTPServer. I was able to download the file but when i'm trying to open the same, i'm unable to see the contents.
FYI-If the PDF file size is 735kb, i'm able to see the contents. But if the file size is 18kb, i'm unable to see the contents of the PDF File.

I'm pasting the code which i was using to download,

//The following stmt, gets the file contents in the form of byte array.

byte [] aFileContent = ftpClient.downloadFile("csfbsda.pdf");
InputStream is = new ByteArrayInputStream(aFileContent);
BufferedInputStream in = new BufferedInputStream(is);
FileOutputStream file = new FileOutputStream("C:/csfbsda.pdf");
BufferedOutputStream out = new BufferedOutputStream(file);
 
Ranch Hand
Posts: 445
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try flushing the output stream By the way, you seem to have lost your way...
 
Purna Nagabhyru
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Thanks for your reply. The same what you have mentioned i'm already using that in my code. But not succeded. In the previous mail i haven't posted that code, please find the total code,


//Calling file download method of FTPClient to download "abcd.pdf".

byte []afileContent = ftpClient.downloadFile("abcd.pdf");

InputStream is = new ByteArrayInputStream(aFileContent);
BufferedInputStream in = new BufferedInputStream(is);

//Storing the file on to our local machince.
FileOutputStream file =
new FileOutputStream("C:/abcd.pdf");
BufferedOutputStream out = new BufferedOutputStream(file);
int i;
out.flush();
while ((i = in.read()) != -1) {
out.write(i);
}

out.flush();
out.close();
 
Why should I lose weight? They make bigger overalls. And they sure don't make overalls for tiny ads:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic