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

  • SEARCH
  • Home
  • 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 8060433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:59:22+00:00 2026-06-05T09:59:22+00:00

Okay, so what I’m trying to do is create a java program that uses

  • 0

Okay, so what I’m trying to do is create a java program that uses data obtained from a web service. I can get the data, but it’s in the format of an XML document, and when I print it to the (Eclipse) console, there are spaces between every letter and the replaceAll method doesn’t work. The relevant part of the code is below.

BufferedReader reader = new BufferedReader(new InputStreamReader(new URL(webAdress).openStream()));
String XMLcode = reader.readLine();
XMLcode = XMLcode.concat(reader.readLine());
XMLcode = XMLcode.replaceAll(" ", "");
System.out.println(XMLcode); //in the finished program, I will do something with the data in the XML document.

The results look like this-

þÿ < ? x m l  v e r s i o n = " 1 . 0 " e n c o d i n g = " U T F - 8 " ? >

followed by the actual data I’m looking for. Some internet searches implied that the þÿ meant that this was a text-encoding problem, but all methods I could find for converting UTF-8 into UTF-16 did not help (they do, however, change the þÿ into ??). Does anybody have any idea how to fix this, or know of a “standard” way to read XML that does not require it available in a file?

NOTE- I did not make the web service in question, and as such cannot modify it and don’t really know how it works.

  • 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-06-05T09:59:24+00:00Added an answer on June 5, 2026 at 9:59 am

    Maybe is a good idea try with:

    new BufferedReader(new InputStreamReader(new URL(webAdress).openStream(), "UTF-16"));
    

    you can use the following code to test it:

    import java.io.File;
    import java.io.FileInputStream;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.Reader;
    
    public class CharsetChanging {
    
        public static void main(final String[] args) throws IOException {
    
            File infile = new File("/tmp/utf16.txt");
    
            FileInputStream inputStream = new FileInputStream(infile);
    
            Reader in = new InputStreamReader(inputStream, "UTF-16");
    
            int read;
    
            while ((read = in.read()) != -1) {
                System.out.print(Character.toChars(read));
            }
    
            in.close();
        }
    }
    

    just replace new FileInputStream(infile) with new URL(webAdress).openStream()

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

Sidebar

Related Questions

Okay, so I'm trying to make a game that uses this algorithm: http://www.codeproject.com/Articles/15573/2D-Polygon-Collision-Detection But
Okay I have a large CRUD app that uses tabs with Forms embedded in
Okay, so in this program I'm making, users will be able to create shortcuts
Okay people, I'm sure someone has had this issue and can help me out.
Okay so the title may be a bit misleading. What I am trying to
Okay so I made this program to help me out with my homework and
Okay, I'm trying to reverse engineer a feature on a website I found -
Okay, I have a WinForms C# program I am writing in Visual Studio 2010
Okay so here is what I'm trying to accomplish. First of all below table
Okay So this doesnt make sense to me.... maybe someone can shed some light.

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.