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.
fileReader.readreturns 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 novFileReaderinherited fromReader(viaInputStreamReader), which works with characters, not bytes? Show me how. - faoxisbyte[]->char[]andout.write->stringBuilder.append- zRrr