-3

I have a list of french words where I am trying to search in my database. The words are "thé Mariage frères", "thé Lipton" etc. While I am reading my file in java, it shows the words as "thé Lipton", "thé Mariage frères". It fails to get the correct words. I don't know how to correct my errors.

Help me, please!!!

prabhu
  • 103
  • 1
  • 3
  • 15
  • Did you try anything? If yes then add your code to the question. – Ravikumar Oct 19 '16 at 09:20
  • Check the database encoding, connection encoding, editor encoding, JSP and HTML encoding... it must be the same: UTF-8 – Sefran2 Oct 19 '16 at 09:21
  • @Ravikumar No, I didn't face this error earlier, So I don't have any clue to solve... – prabhu Oct 19 '16 at 09:24
  • @Ravikumar Scanner s = new Scanner(new File("French_Tea_keywords/filter_keywords.txt")); ArrayList brand_Name = new ArrayList(); while (s.hasNext()){ String token = s.nextLine(); brand_Name.add(token); } String[] stringArr = brand_Name.toArray(new String[0]); s.close(); – prabhu Oct 19 '16 at 09:26
  • 1
    @prabhu Try creating Scanner object like this `Scanner s = new Scanner(new File("French_Tea_keywords/filter_keywords.txt"), "UTF8"); ` – Ravikumar Oct 19 '16 at 09:32
  • @Ravikumar Thank you so much!!! Solved.. – prabhu Oct 19 '16 at 09:38
  • @prabhu Nice, happy to help :) – Ravikumar Oct 19 '16 at 09:42

3 Answers3

0

You file is in one encoding (maybe latin1/iso-8859-1) and you're reading your file in another encoding.

See if this port helps How to read a file in Java with specific character encoding?

Community
  • 1
  • 1
djointster
  • 346
  • 3
  • 12
0

Try this.

    try (FileInputStream fis = new FileInputStream("input.txt");
        InputStreamReader isr = new InputStreamReader(fis, StandardCharsets.UTF_8);
        BufferedReader reader = new BufferedReader(isr)) {
        String line;
        while ((line = reader.readLine()) != null)
            System.out.println(line);
    }
0

Try creating Scanner object like this

Scanner s = new Scanner(new File("French_Tea_keywords/filter_keywords.txt"), "UTF8");

prabhu
  • 103
  • 1
  • 3
  • 15