?
Solved

Cpying PDF file from distant server with java

Posted on 2004-04-27
3
Medium Priority
?
232 Views
Last Modified: 2010-03-31
How to write a java program which copy a PDF file from a distant server to ower machine, this portion of program do this but the PDF file contain an error while reading by AdobAcrobeat.
try
 {
   URL urlFichierHello = new URL("http://www.loria.fr/projets/TALN/actes/Recital/posters/nouali.pdf");
   URLConnection connexion   = urlFichierHello.openConnection ();
   InputStream   fluxFichier = connexion.getInputStream ();
   byte contenuFichier [ ] = new byte [connexion.getContentLength ()];
   int  octetsLus = fluxFichier.read (contenuFichier);
   fluxFichier.close ();
   try
     {
       RandomAccessFile  file_to_ponc = new RandomAccessFile("C:\\1.pdf","rw");
       file_to_ponc.write(contenuFichier);
       file_to_ponc.close();
      }
      catch(java.io.IOException e){e.printStackTrace();}  
 }
 catch (Exception e){e.printStackTrace();}
thanks
0
Comment
Question by:zs_said
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 400 total points
ID: 10927852
I would alter your program a little. There's no need to use a RAF:


InputStream   fluxFichier = connexion.getInputStream ();
FieOutputStream out = new FileOutputStream(new File("c:/1.pdf"));
final int BUF_SIZE = 8192;
byte contenuFichier [ ] = new byte [BUF_SIZE];
int bytesRead = -1;
while ((bytesRead = fluxFichier.read(contenuFichier)) > -1) {
    out.write(contenuFichier, 0, bytesRead);
}
fluxFichier.close();
out.close();

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month9 days, 13 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question