0

i'm trying to use Files.readAllLines to read a file and editing it.

List<String> l = Files.readAllLines(manejador.getArchivo().toPath(), StandardCharsets.UTF_8);

The file has a list of games and its players:

ID: Fm550.0
Federico Schmidt
Iván Petrini
Germán Gómez
Tomás  Perotti
ID: VO101000.0
Alex Morgan

So then, i want to check every position in the list to see if it is equals to some ID.

The problem is that when i use Files.readAllLines, i get this:

?ID: Fm550.0
Federico Schmidt
Iván Petrini
Germán Gómez
Tomás  Perotti
ID: VO101000.0
Alex Morgan

How can i get rid of that ? at the beggining?

Jordi Castilla
  • 26,609
  • 8
  • 70
  • 109
Ivan
  • 69
  • 6
  • That character is probably in your file - how did you create the file? – assylias Dec 16 '15 at 15:45
  • 3
    Maybe it's a BOM. Look at your text file with a hex editor. – Mr Lister Dec 16 '15 at 15:46
  • 2
    UTF-8 files *may* start with a BOM ([Byte Order Mark](https://en.wikipedia.org/wiki/Byte_order_mark#UTF-8)). You should open the file in a text editor (e.g. Notepad++) and save it without the BOM. From the wiki: *"The Unicode Standard **permits** the BOM in UTF-8, **but does not** require or **recommend its use**."* – Andreas Dec 16 '15 at 16:02
  • Possible duplicate of [Reading UTF-8 - BOM marker](http://stackoverflow.com/questions/4897876/reading-utf-8-bom-marker) – K.Nicholas Dec 16 '15 at 17:45

1 Answers1

0

While your question is slightly different, i.e., not a duplicate of Reading UTF-8 - BOM marker because it appears you may not have known the issue of BOM's in UTF-8, there is an answer for dealing with BOM in UTF-8 files in Java in the link above.

Community
  • 1
  • 1
K.Nicholas
  • 10,956
  • 4
  • 46
  • 66