在CSHARP服务器上保存JAVA读取的映像

在CSHARP服务器上保存JAVA读取的映像,java,c#,tcp,server,client,Java,C#,Tcp,Server,Client,我正在尝试在CSHARP-SERVER上保存来自JAVA-CLIENT的映像。 我做了以下工作: 以字节数组形式读取图像(JAVA-CLIENT) 将字节数组转换为base64字节数组(JAVA-CLIENT) 将base64字节数组发送到CSHARP-SERVER(JAVA-CLIENT) 接收base64字节数组(CSHARP-SERVER) base64字节数组到base64字符串(CSHARP-SERVER) 将base64字符串解码为utf8字符串(CSHARP-SERVER) 获取u

我正在尝试在CSHARP-SERVER上保存来自JAVA-CLIENT的映像。 我做了以下工作:

  • 以字节数组形式读取图像(JAVA-CLIENT)
  • 将字节数组转换为base64字节数组(JAVA-CLIENT)
  • 将base64字节数组发送到CSHARP-SERVER(JAVA-CLIENT)
  • 接收base64字节数组(CSHARP-SERVER)
  • base64字节数组到base64字符串(CSHARP-SERVER)
  • 将base64字符串解码为utf8字符串(CSHARP-SERVER)
  • 获取utf8字符串字节(CSHARP-SERVER)
  • 将字节另存为映像(CSHARP-SERVER)
  • 现在我无法在windows imageviewer中打开此图像文件

    但我注意到:

    • csharp服务器上的base64字符串与我的客户端上的相同
    • 我比较了两个文件(客户端和服务器)。。在记事本上打开它们,发现它们并不相等
    如何在我的服务器上保存此图像? 最好的方法是什么? 是否有开源的JavaCSharpBridge库

    这是我的密码:

    public class Program {
    
    
    static String getBase64StringFromBytes(byte[] bytes)
    {
        String b64 = null;
        try {
            //To Base64-String
            b64 = new String(Base64.getEncoder().encode(bytes),"UTF-8");
            //UTF-8
            return b64;
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return null;
    
    }
    
    public static void main(String args[]) {
        //1.Read image as byte array
        byte[] data = FileManager.readeFile();
        //2.1 Convert byte array to base64 string
        String str64 = getBase64StringFromBytes(data);
        //2.2 Convert base64 string to base64 byte array
        byte[] b64Bytes = str64.getBytes();
        //3.Send base64 byte array to csharp
        Sender.sendData(b64Bytes);
    }
    
    }

    CSHARP服务器:

    class Program
    {
        static string getStringFromBase64Bytes(byte[] base64Bytes)
        {
            //5.Base64 byte array to base64 string   
            string s64 = Encoding.UTF8.GetString(base64Bytes);      
            //6.Decode base64 string to utf string
            string utf8 = Encoding.UTF8.GetString(Convert.FromBase64String(s64)); //Base64-String to UTF-8 String      
            return utf8;
        }
    
        static void Main(string[] args)
        {
            Receiver mReceiver = new Receiver();
            //4.Receive base64 byte array
            byte[] data = mReceiver.waitForData();      
    
            string strDataTest = getStringFromBase64Bytes(data);
            //7.Get UTF-8 bytes
            byte[] fData = Encoding.UTF8.GetBytes(strDataTest);
            Console.WriteLine("DATA SIZE: " + fData.Length);
            //8.Save file
            File.WriteAllBytes("mFile.png", fData);
    
            mReceiver.closeAll();
            Console.ReadLine();
    
        }
    }
    

    请显示实际代码-已清理请参阅以获取指导。。。(步骤4-7也很奇怪-您可能想阅读一些关于在C#中处理base64的内容)当您还可以直接发送和接收字节数组时,为什么要进行所有这些转换?简单地说,您只需执行
    Sender.sendData(FileManager.readeFile())
    File.writealBytes(“mFile.png”,mReceiver.waitForData())
    。lol您是对的。但是为什么我可以直接使用Sender.sendData和File.writealBytes呢?在csharp中,字节是有符号字节,java是无符号字节?