I transfer the file-image program on qt via the Internet on sockets:

QFile file("/home/user/Изображения/hats.jpg"); if(!file.open(QIODevice::ReadWrite)) { qDebug() <<"Error open file";} QByteArray arrfile = file.readAll(); pClientSocket->write(arrfile); pClientSocket->flush(); Я принимаю файл програмкой на android: tc.in = client.getInputStream(); tc.isr = new InputStreamReader(client.getInputStream(), "UTF-8"); tc.br = new BufferedReader(isr); while (true) { try { int bufsize = 8192; byte[] buf = new byte[bufsize]; int rlen = tc.in.read(buf); if(tc.br.ready() && rlen>-1) { File dst = new File("/storage/sdcard0/Download/ggg/hats.jpg"); OutputStream out = new FileOutputStream(dst); out.write(buf, 0, rlen); while ((rlen = tc.in.read(buf)) > 0) { out.write(buf, 0, rlen); DebagClass.mLog("Avaiaiblerlen="+rlen); DebagClass.mLog("Avaiaible="+tc.in.available()); DebagClass.mLog("space0"); File src = new File("/storage/emulated/0/Download/hats.jpg"); DebagClass.mLog("space src="+src.getTotalSpace()); DebagClass.mLog("space dest="+dst.getTotalSpace()); } DebagClass.mLog("space20"); out.close(); File src = new File("/storage/emulated/0/Download/hats.jpg"); DebagClass.mLog("space2 src="+src.getTotalSpace()); DebagClass.mLog("space2 dest="+dst.getTotalSpace()); } 

Everything works fine the file is transferred, even file sizes are the same. But instead of the picture opens a blank screen. For some reason, a debugging message is not displayed after the while loop, it seems to be displayed. What am I not doing wrong? ps By the way, I need a BufferedReader, just because there is ready (), so it hangs on it and does not spin in an infinite loop, it seems to me that it eats less resources, although maybe I'm wrong, hs. And maybe because of this, I will check. tc is just a class object where variables are stored.

  • And you do not display on the screen, and save the received data to the file. And then byte-by-byte compare with the original data. - Vladimir Martyanov
  • one
    In short, the problem is solved: this is my side battle; I’ve sent another 1 packet so he added a line and the picture wasn’t read, I don’t know whether to write the correct answer or not, the code should be still working. - Madoka Magica

0