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 7959029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:30:34+00:00 2026-06-04T04:30:34+00:00

I’ve a simple web service that lists a variable number of foreign languages. Some

  • 0

I’ve a simple web service that lists a variable number of foreign languages.

Some of them are listed in native charset (like Chinese, for example).

I must read this from a webpage and dynamically add them to a JComboBox.

Actually I’m reading them in this way:

public static Vector getSiteLanguages() {
    System.out.println("Reading Home from " + Constants.HOME);
    URL url;
    URLConnection connection;
    BufferedReader br;
    String inputLine;

    String regEx = "<option.*value=.([A-Z]*).>(.*)</option>";
    Pattern pattern = Pattern.compile(regEx);       
    Matcher m;
    Vector siteLangs = new Vector(); 

    try {
        url = new URL( Constants.HOME);
        connection = url.openConnection();
        br = new BufferedReader(new InputStreamReader(connection.getInputStream()));

        while ((inputLine = br.readLine()) != null) {
            m = pattern.matcher(inputLine);
            while ( m.find()) {
                System.out.println(m.group(1) + "->" + m.group(2) );
                siteLangs.add(m.group(2));
            }
        }
        br.close();
    } catch (IOException e) {
        return siteLangs;
    } 

    return siteLangs;       
}

Then in the JFrame class I’m doing this:

Vector siteLangs = Language.getSiteLanguages();
JComboBox siteLangCombo = new JComboBox(siteLangs);

But in this way all non-latin languages are lost…

How do I preserve non-latin info in this situation?

  • 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-04T04:30:35+00:00Added an answer on June 4, 2026 at 4:30 am

    The InputStreamReader uses by default the platform default character encoding to convert bytes to characters. The website is apparently using a different character encoding to convert characters to bytes in the HTTP response. You need to check the HTTP Content-Type response header which one it is.

    String contentType = connection.getHeaderField("Content-Type");
    

    Assuming that it’s UTF-8, which is these days the most commonly used character encoding in websites who strive to world domination, here’s how you should be specifying it during the construction of the InputStreamReader in your code:

    br = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
    

    See also:

    • Using java.net.URLConnection to fire and handle HTTP requests

    Unrelated to the concrete problem, the Vector is a legacy class which has been replaced by the List interface since 1998. Are you sure that you’re reading up-to-date resources during your Java learning spree? Further, regex should not be your first choice when you just need to parse HTML. This is Java, not PHP. Use a normal HTML parser. You may find Jsoup helpful in this. The whole code which you’ve so far can then be brought back to two or three lines.

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Seemingly simple, but I cannot find anything relevant on the web. What is the
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into

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.