如何通过套接字将编码文件从Delphi发送到Android

时间:2014-09-19 08:17:33

标签: java android delphi sockets serversocket

我尝试通过套接字从delphi发送编码文件到android 我使用的是delphi xe4

这是我的delphi代码

procedure sendData();
begin
  dbdata = encodeFile('D:\data.sql');
  Memo1.Text := dbdata;
  ssMobile.Socket.Connections[cmbDevice.ItemIndex].SendText(dbdata + #10#13);
end;

这是我的安卓代码

private void receiveFile() {
    try {
        BufferedReader input = new BufferedReader(new InputStreamReader(
                socket.getInputStream()));
        String read = input.readLine();
        if (!read.isEmpty()) {
            if (read.contains("enddb")){
                isFile = false;
            }
            byte[] dbAsBytes = read.getBytes();
            File filePath = new File(Environment.getExternalStorageDirectory()+"/data.sql");
            FileOutputStream os = new FileOutputStream(filePath, true);
            os.write(dbAsBytes);
            os.flush();
            os.close();
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}

这是我的memo1.text

U1FMaXRlIGZvcm1hdCAzABAAAQEAQCAgAAAAPAAAAAkAAAAAAAAAAAAAAAUAAAAEAAAAAAAAAAkA
AAABAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA8AC3iJw0PowAHBn8AD6cL+Q9u
C5cG1QtuBn8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA...

这是我收到的文件

U1FMaXRlIGZvcm1hdCAzABAAAQEAQCAgAAAAPAAAAAkAAAAAAAAAAAAAAAUAAAAEAAAAAAAAAAkA
U1FMaXRlIGZvcm1hdCAzABAAAQEAQCAgAAAAPAAAAA
U1FMaXRlIGZvcm1hdCAzABAAAQEAQCAgAAAAPAAA
U1FMaXRlIGZvcm1hdCAzABAAAQEAQCAgAAAAPA
U1FMaXRlIGZvcm1hdCAzABAAAQEAQCAgAAAA
U1FMaXRlIGZvcm1hdCAzABAAAQEAQCAgAA
U1FMaXRlIGZvcm1hdCAzABAAAQEAQCAg

我的代码出了什么问题? 我收到的文件与我发送的数据不一样?

0 个答案:

没有答案