我正在尝试通过 wifi 在我的 pc 和 android 设备之间共享文件。奇怪的是文本和音频文件正在完美传输,而图像和视频文件无法呈现。这是主要的代码:
发件人:
BufferedOutputStream writer = new BufferedOutputStream(client.getOutputStream());
InputStream stream = new FileInputStream(file);
while ((read = stream.read(buffer)) != -1)
writer.write(buffer, 0, read);
接收者:
BufferedInputStream input = new BufferedInputStream(client.getInputStream());
OutputStream outputStream = new FileOutputStream(file, true);
while (!store.complete) {
read = input.read(buffer, 0 , MAX_SIZE_OF_BUFFER);
String data = new String(buffer);
// Need to do some data manipulation (like removing a string which i appended
// while sending )
outputStream.write(data.getBytes());
}
注意:即使接收端的图像/视频文件的大小与发送的文件相同,仍然无法渲染。
提前致谢!!:)