private void read() { String path = "/Users/pavel/Desktop/test/target_text.txt"; try (BufferedInputStream in = new BufferedInputStream( new FileInputStream(path))) { byte[] bytes = new byte[1024]; int amountData = in.read(bytes, 0, 1024); while (amountData != -1 && amountData == 1024) { sb.append(new String(bytes, "UTF8")); amountData = in.read(bytes, 0, 1024); } if (amountData != -1) { byte[] residue = new byte[amountData]; System.arraycopy(bytes, 0, residue, 0, residue.length); sb.append(new String(residue, "UTF8")); } System.out.println(sb); } catch (IOException e) { e.printStackTrace(); } } int amountData = in.available()%1024; for(int n=0; n