Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2011
    Posts
    6
    Rep Power
    0

    Default Save File From URL

    Hi I am trying to save PDF File from an URL

    Note:URL will not have file name and URL will hit OBIEE server gets the file.

    i am able to create pdf file but pdf file is not dislayed
    Last edited by Rajesh Panduru; 08-18-2011 at 08:44 AM.

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,415
    Rep Power
    25

    Default

    What is in the file that you receive from the server? Open it in an editor to see what you have written to disk.
    You haven't shown the code you are using to read the file and save it to disk. Are you reading and writing the bytes of the file as bytes or as text?

  3. #3
    Join Date
    Aug 2011
    Posts
    6
    Rep Power
    0

    Default

    URL myURL = new URL("http://XXXXXX:9704/XXX/XXXX.dll?Go&Path=XXXXXXXX&NQUser=XXXX&NQPassword=X XXX&Action=download&format=pdf");
    URLConnection myURLConnection = myURL.openConnection();
    myURLConnection.connect();


    BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
    BufferedWriter out = new BufferedWriter(new FileWriter("d:/TM/test.pdf"));
    char[] cbuf=new char[255];
    while ((in.read(cbuf)) != -1) {
    out.write(cbuf);
    }
    in.close();
    out.close();
    aboive is the sample code i am working on it this will display pdf file in browser but i want to write this respne in pdf.

  4. #4
    Join Date
    Aug 2011
    Posts
    6
    Rep Power
    0

    Default

    we will get pdf format from the server.when i try to run this url on browser it will ask for open/save dialouge window when you say open pdf format file will be opened in browser.

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default

    That won't display in a browser since it is not going to a response stream...I suspect you mean something else with that.

    Anyway, it's as Norm guessed...you are saving it as text. Use the InputStream directly from url.openStream() and a FileOutputStream instead of a FileReader, because you are messing up the bytes in the PDF.

Similar Threads

  1. Replies: 3
    Last Post: 06-21-2011, 04:51 PM
  2. Save .txt file
    By Moose in forum Java Applets
    Replies: 1
    Last Post: 10-27-2010, 11:59 PM
  3. save file based on file extension
    By masa in forum AWT / Swing
    Replies: 4
    Last Post: 05-11-2010, 11:17 AM
  4. Replies: 0
    Last Post: 03-05-2010, 04:21 AM
  5. Save file
    By dejos456 in forum New To Java
    Replies: 4
    Last Post: 11-28-2009, 03:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •