I can not understand from where the incomprehensible symbol in the text is taken. Created a file with the following contents:

Киев Нью-Йорк Амстердам Вена Мельбурн 

I process it with this code:

  BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); FileReader fileReader = new FileReader("/home/sergei/file1.txt"); char buff[] = new char[1024]; StringBuilder stringBuilder = new StringBuilder(); while (fileReader.read(buff) > 0) { stringBuilder.append(buff); } String strings[] = stringBuilder.toString().split("\\s"); for (String string : strings) { System.out.println(string); } fileReader.close(); 

At the end, the character is a blank character ( "" ). I do not understand where it comes from. The debagger shows: value = {char[986]@472} .

Where does this unfortunate character come from? There is no strength to fight with him. Type checking string == "" fails.

  • As a working crutch, you can do the string trim () - YuriySPb
  • Your file at the end seems to have a newline. Here it is read and read at the very end. - KoVadim
  • 2
    you incorrectly add the read data to stringbuilder, fileReader.read returns how many bytes were actually read, and you paste the entire array at once, which most likely is not completely filled up, so the tail of your string consists of characters with code 0. - zRrr nov
  • @zRrr why byte? Isn't FileReader inherited from Reader (via InputStreamReader ), which works with characters, not bytes? Show me how. - faoxis
  • Typical way to transfer data from input to output - ru.stackoverflow.com/a/18446/190934 . For your case, just byte[] -> char[] and out.write -> stringBuilder.append - zRrr

0