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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:10:40+00:00 2026-06-12T14:10:40+00:00

I’m experiencing an interesting issue at the moment. I’m trying to read this file,

  • 0

I’m experiencing an interesting issue at the moment.

I’m trying to read this file, which contains the 1000 most common english words in alphabetical order, in java:

http://www.file-upload.net/download-6679295/basicVocabulary.txt.html

This is a snippet at the beginning of the file:

a
able
about
above
according
account
across
act
action
added
afraid
after

My problem now is that, although it seems I’m reading the txt-file correctly, the first line is missing later on in my resultset/resultlist. In this case this is the letter “a”, since it stands at the first position.

For making you able to reproduce my problem, please try this sample code with the txt-file above and see it for yourself (Don’t forget to update the filepath). I have added the console output that comes for me in comments.

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class MyWrongBehaviour {

public static void main(String[] args){
    MyWrongBehaviour wrong = new MyWrongBehaviour(); 

    List<String> list = wrong.loadLanguageFile(); 

    System.out.println("size of the list: " + list.size()); //Answer is 1000, that's the correct size

    for(String s : list){
        System.out.println(s); // "a" will appear, so it is somehow included
    }

    if(list.contains("a")){
        System.out.println("found \"a\""); // doesn't get written on the console, can't find it
    }

    for(String s : list){
        if(s.equals("a")){
            System.out.println("found \"a\""); // never gets written, can't find it
        }
    }


}

private List<String> loadLanguageFile() {
    List<String> result = null;
    try (InputStream vocIn = getClass().getResourceAsStream(
            "/test/basicVocabulary.txt")) {

        if (vocIn == null) {
            throw new IllegalStateException(
                    "InputStream for the basic vocabulary must not be null");
        }

        BufferedReader in = new BufferedReader(new InputStreamReader(vocIn,
                "UTF-8"));

        String zeile = null;

        result = new ArrayList<>();
        while ((zeile = in.readLine()) != null) {
            result.add(zeile.trim());
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

    return result;
}


}

Has someone an idea why this is happening and what I can do to fix it? My thoughts are that there might be a charset error, although I saved the file as UTF-8, or that there is somehow an invisible character that corrupts the file, but I don’t know how to identify it.

Btw: I’ve used a Hashset before, but with a Set the first line didn’t even get added. Now it gets added, but can’t find it.

Thanks for every answer and thought you’re sharing with me.

  • 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-12T14:10:41+00:00Added an answer on June 12, 2026 at 2:10 pm

    The file starts with a byte-order mark which indicates that it’s UTF-8, so the first line is actually equivalent to “\ufeffa” (i.e. two characters, U+FEFF and then ‘a’), which then isn’t equal to “a”.

    One way of stripping this is just to use:

    result.add(zeile.trim().replace("\ufeff", ""));
    

    After that change, your code works as expected. There may be a better way of removing byte-order marks in Java, but I don’t know it offhand.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm trying to select an H1 element which is the second-child in its group
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text

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.