From 70fbc9ccde2d0bd636cebc07d38a0c7c8961896e Mon Sep 17 00:00:00 2001 From: Jonas Thiel Date: Wed, 15 May 2013 16:25:03 +0200 Subject: [PATCH] Read input file always with UTF8 encoding --- input.txt | 4 +++- src/WordsReader.java | 11 ++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/input.txt b/input.txt index 126dfb0..e7850b3 100644 --- a/input.txt +++ b/input.txt @@ -153,4 +153,6 @@ firefox,5 site,5 china,5 clients,5 -widget,5 \ No newline at end of file +widget,5 +ser-feliç,25 +santé,25 \ No newline at end of file diff --git a/src/WordsReader.java b/src/WordsReader.java index 02d6fd7..21efe39 100644 --- a/src/WordsReader.java +++ b/src/WordsReader.java @@ -1,9 +1,6 @@ import wordcram.Word; -import java.io.BufferedReader; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.IOException; +import java.io.*; import java.util.ArrayList; /** @@ -16,6 +13,7 @@ import java.util.ArrayList; * WEIGHT will be parsed as a Float */ public class WordsReader { + private static final String UTF8 = "UTF-8"; private String file; public static final String SEPARATOR = ","; @@ -36,10 +34,13 @@ public class WordsReader { BufferedReader reader; try { - reader = new BufferedReader(new FileReader(file)); + reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), UTF8)); } catch (FileNotFoundException e) { e.printStackTrace(); return new Word[0]; + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + return new Word[0]; } String line;