class
FileReceiver
extends
Thread{
Socket socket;
DataInputStream dis;
FileOutputStream fos;
BufferedOutputStream bos;
public
FileReceiver(Socket socket) {
this
.socket = socket;
}
@Override
public
void
run() {
try
{
dis =
new
DataInputStream(socket.getInputStream());
String fName =
"sample.jpg"
;
File f =
new
File(Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator +
"temp"
+ File.separator+fName);
fos =
new
FileOutputStream(f);
bos =
new
BufferedOutputStream(fos);
int
len=
0
;
int
size =
8192
;
int
cnt=
0
;
byte
[] data =
new
byte
[size];
while
((len = dis.read(data)) > -
1
) {
bos.write(data,
0
, len);
cnt++;
Log.e(
"error"
,String.valueOf(cnt));
}
bos.flush();
bos.close();
fos.close();
dis.close();
}
catch
(IOException e) {
e.printStackTrace();
}
}
}