我正在尝试将 XML 文件从桌面服务器传输到 Android 客户端,但我在 Android 设备上只获得了整个文件的 1024 字节。我的代码是:
将文件从桌面服务器发送到 Android 客户端:
byte[] mybytearray = new byte[(int) filePianificazione.length()];
BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(filePianificazione));
bufferedInputStream.read(mybytearray, 0, mybytearray.length);
bufferedInputStream.close();
out.write(mybytearray, 0, mybytearray.length);
out.flush();
从Android客户端接收文件到服务器:
byte[] mybytearray = new byte[1024];
FileOutputStream fos = new FileOutputStream(file.getAbsolutePath());
BufferedOutputStream bos = new BufferedOutputStream(fos);
int bytesRead = in.read(mybytearray, 0, mybytearray.length);
bos.write(mybytearray, 0, bytesRead);
bos.close();