0
當我收到文件時,它將WHOLE文件添加到'data'的0索引中。我如何做到這一點,所以每一個接收的文件行都進入了一個新的索引,基本上就像我試圖做的那樣。套接字文件傳輸不正確
public Downloader(Socket socket) {
List<String> data = new ArrayList<String>();
try {
InputStream input = socket.getInputStream();
byte[] buffer = new byte[socket.getReceiveBufferSize()];
int bytesReceived = 0;
while ((bytesReceived = input.read(buffer)) > 0) {
String line = new String(buffer, 0, bytesReceived);
if (line.trim().length() > 0) {
data.add(line);
}
}
Data.rawData = data;
input.close();
socket.close();
} catch (Exception e) {
e.printStackTrace();
}
}
謝謝你現在的作品 – CBennett