コンピューターの Windows フォーム アプリケーションに .txt ファイルを送信する Android アプリを作成しようとしています。問題は、ファイル全体が送信されないことです (問題が送信側にあるのか受信側にあるのかはわかりませんでした)。.txt ファイルの途中からランダムな部分だけを受信側に取得します。私は何を間違っていますか?奇妙なことは、それが数回完全に機能したことですが、今ではファイルの先頭または末尾を取得できません。
Android アプリは Java で作成され、Windows フォーム アプリは C# で作成されます。filepath は私のファイルの名前です。ここで何が問題なのですか?
Android アプリのコード (送信ファイル)
//create new byte array with the same length as the file that is to be sent
byte[] array = new byte[(int) filepath.length()];
FileInputStream fileInputStream = new FileInputStream(filepath);
BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream);
//use bufferedInputStream to read to end of file
bufferedInputStream.read(array, 0, array.length);
//create objects for InputStream and OutputStream
//and send the data in array to the server via socket
OutputStream outputStream = socket.getOutputStream();
outputStream.write(array, 0, array.length);
Windows フォーム アプリのコード (受信ファイル)
TcpClient tcpClient = (TcpClient)client;
NetworkStream clientStream = tcpClient.GetStream();
byte[] message = new byte[65535];
int bytesRead;
clientStream.Read(message, 0, message.Length);
System.IO.FileStream fs = System.IO.File.Create(path + dt);
//message has been received
ASCIIEncoding encoder = new ASCIIEncoding();
System.Diagnostics.Debug.WriteLine(encoder.GetString(message, 0, bytesRead));
fs.Write(message, 0, bytesRead);
fs.Close();