Android-Send / Receive byte []通过TCP Socket

时间:2011-12-14 14:05:06

标签: java android

我想通过TCP套接字连接在byte []中发送/接收sqlite数据库文件(* .db)?

1 个答案:

答案 0 :(得分:1)

这是:

Socket socket = new Socket(host, port);
FileInputStream fis = new FileInputStream(yourFile);
OutputStream out = socket.getOutputStream();
byte[] buffer = new byte[9182];
int nBytesRead = 0;
while ((nBytesRead = fis.read(buffer) != -1)
{
    out.write(buffer, 0, nBytesRead);
}
out.flush();
out.close();
fis.close();