Яву учу первый месяц урывками, хочу разобраться. Это часть моего тестового задания чтобы поступить курсы по java.
у меня есть текстовый файл dict.txt
текст
виде
изображение
файл
я пытаюсь сделать с ним это:
final String dictfile = "dict.txt";
Set<String> slovar = new HashSet<String>();
try {
slovar.addAll(Files.readAllLines(Paths.get(dictfile), Charset.defaultCharset()));
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(slovar); //[текст, изображение, файл, виде]
в консоли выводится [·текст, изображение, файл, виде] что это за точка "·" перед словом "текст"? откуда она берется и как мне поправить код/руки чтобы в slovar считывалось именно то что содержится в файле?
файл dict.txt UTF-8 лишних пробелов до и после слова "текст" нет.
P.S. пробовал по другому, результат тот же: [·текст, изображение, файл, виде]
final String dictfile = "dict.txt";
Set<String> slovarr = new HashSet<String>();
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(dictfile));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
String line;
try {
while ((line = reader.readLine()) != null) {
slovarr.add(line);
}
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(slovarr);
Нашел ответ на мой вопрос тут, оказывается:
1.точка что мне не нравилась называется \uFEFF
2.в начале UTF файла есть символ BOM(Byte Order Mark) и с помощью Notepad++ можно сохранить файл в UTF без BOM.
That's a problem related to BOM (Byte Order Mark) character. Byte Order Mark BOM is a Unicode character used for defining a text file byte order and comes in the start of the file. Eclipse doesn't allow this character at the start of your file, so you must delete it. For this purpose, use a rich text editor, such as Notepad++, and save the file with encoding "UTF-8 without BOM." That should remove the problem.
Сборка персонального компьютера от Artline: умный выбор для современных пользователей