【发布时间】:2012-09-11 20:07:44
【问题描述】:
我正在尝试通过套接字从 python 服务器向 android 客户端发送文件(具体为 png)。我知道我的 python 服务器正在发送数据,我只是不知道如何在 android 端接收数据。这是接收文件的代码。
String path = Environment.getExternalStorageDirectory().toString() +"/tmp/test.png";
try {
socket = new Socket("192.168.1.129", 29877);
is = socket.getInputStream();
out = new FileOutputStream(path);
byte[] temp = new byte[1024];
for(int c = is.read(temp,0,1024); c > 0; c = is.read(temp,0,1024)){
out.write(temp,0,c);
Log.d("debug tag", out.toString());
}
Log.d("debug tag", temp.toString());
Bitmap myBitmap = BitmapFactory.decodeByteArray(temp, 0, temp.length);
imageView.setImageBitmap(myBitmap);
感谢您的建议。
【问题讨论】: