Solved

Cpying PDF file from distant server with java

Posted on 2004-04-27
3
227 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 100 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

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

724 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