Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7602531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:26:06+00:00 2026-05-30T23:26:06+00:00

I am having trouble doing a simple download of an XML file from a

  • 0

I am having trouble doing a simple download of an XML file from a URL. I have looked around this site for a while already and followed most of the examples on how to download a file with the proper encoding as far as I can tell, however I must be doing something wrong because I am not getting the desired output. At the moment my code looks like this.

            Catalog cat = (Catalog)obj;

            String datasetURL = cat.getID()+"@datasets";

            URL dataURL = new URL(datasetURL);

            InputStream iStream = dataURL.openStream();

            int count = iStream.available();
            char content[] = new char[count];

            InputStreamReader isReader = new InputStreamReader(iStream,"UTF-8");

            BufferedReader buffRead = new BufferedReader(isReader);

            buffRead.read(content, 0, count);

            String contentAsString = new String(content, 0,count);

            FileWriter fstream = new FileWriter("src/main/resources/datasets.xml");
            BufferedWriter out = new BufferedWriter(fstream);

            out.write(contentAsString);
            out.close();

This seems to work correctly however the xml file is displaying characters like:
�Ksǵ���p� etc in Eclipse and appears as �Ksǵ���Žp� in notepad++. I dont know what to do because I have already added the encoding to the InputStreamReader so I thought that would solve this problem.

Also I am not too familiar with RDF but the xml file has an RDF tag in it. Would that make any difference?

<?xml version='1.0' encoding='UTF-8'?>
<r:RDF xmlns:s="http://www.w3.org/TR/1999/PR-rdf-schema-19990303#"   xmlns:r="http://www.w3.org/1999/02/22-rdf-syntax-ns#" etc.. 

Thanks much.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T23:26:07+00:00Added an answer on May 30, 2026 at 11:26 pm

    I found that the problem actually was because the file was zipped! Here is the code I am using now which has successfully downloaded the file.

                Catalog cat = (Catalog)obj; 
    
                indexName += "."+cat.getInternalID();
    
                String datasetURL = cat.getID()+"@datasets";
    
                URL dataURL = new URL(datasetURL);
    
                URLConnection conn = dataURL.openConnection();
    
                String encoding = conn.getContentEncoding();
    
                InputStream is = encoding.equals("gzip")? new GZIPInputStream(conn.getInputStream()) : conn.getInputStream();
    
                BufferedReader in = new BufferedReader(new InputStreamReader(is));
    
                String inputLine;
    
                while ((inputLine = in.readLine()) != null)
                    System.out.println(inputLine);
    
                in.close();
    

    Hope this helps anyone else out there that may be having similar problems.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having some trouble doing a very simple task. I have a rich textbox
This is a seemingly simple problem but I am having trouble doing it in
I am having trouble doing a reverse URL lookup for Django-generated feeds. I have
I'm having trouble to make a simple CRUD in my site. I have a
I am having trouble doing something that is probably pretty simple! I have a
First time doing Python in a while, and I'm having trouble doing a simple
I am having trouble doing this simple task of changing my input box color
I am having trouble doing something simple like the following using (SPSite site =
I'm having a lot of trouble doing something very simple. I have a viewController
Whilst doing exam revision I am having trouble answering the following question from the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.