Java应用程序将XML发送到Python应用程序.他们都在同一台机器上.当我打开收到的文件时,我可以看到额外的行(因为额外的CR).这可能是什么原因?
这是接收者:
f = open('c:/python/python.xml', 'w')
while 1:
print("xxx")
data = socket.recv(recv_frame)
remain_byte = remain_byte - len(data)
print(remain_byte)
f.write(data)
if (something):
break
Run Code Online (Sandbox Code Playgroud)
这是发件人:
while ((bytesRead = file_inp.read(buffer)) > 0) {
output_local.write(buffer, 0, bytesRead);
}
Run Code Online (Sandbox Code Playgroud)
这是原始文件:
<root><CR><LF>
<SONG><CR><LF>
<ARTIST>Coldplay</ARTIST><CR><LF>
</SONG><CR><LF>
</root><CR><LF>
Run Code Online (Sandbox Code Playgroud)
这是收到的:
<root><CR>
<CR><LF>
<SONG><CR>
<CR><LF>
<ARTIST>Coldplay</ARTIST><CR>
<CR><LF>
</SONG><CR>
<CR><LF>
</root><CR>
<CR><LF>
Run Code Online (Sandbox Code Playgroud) 伙计们,ptr如何获得之前的价值?代码很简单,我只是想知道它为什么不存储它在函数中分配的地址值.
#include<stdio.h>
#include<stdlib.h>
void test(int*);
int main( )
{
int temp;
int*ptr;
temp=3;
ptr = &temp;
test(ptr);
printf("\nvalue of the pointed memory after exiting from the function:%d\n",*ptr);
printf("\nvalue of the pointer after exiting from the function:%d\n",ptr);
system("pause ");
return 0;
}
void test(int *tes){
int temp2;
temp2=710;
tes =&temp2;
printf("\nvalue of the pointed memory inside the function%d\n",*tes);
printf("\nvalue of the pointer inside the function%d\n",tes);
}
Run Code Online (Sandbox Code Playgroud)
输出是:
函数内指向的内存值:710
函数内指针的值:3405940
退出函数后指向的内存值:3
退出函数后指针的值:3406180
我有套接字问题.当我在同一台PC上运行服务器和客户端时,即使用"localhost"参数时,会出现此问题.但是,当使用不同的PC时,看不到问题.客户端使用以下代码发送文件:
output_local.write(buffer, 0, bytesRead);
output_local.flush();
Run Code Online (Sandbox Code Playgroud)
然后在另一种方法中,我发送一个命令:
outputStream.write(string);
outputStream.flush();
Run Code Online (Sandbox Code Playgroud)
服务器将命令附加到文件末尾.所以它认为它还没有收到客户的命令.你知道可能导致这个问题的原因吗?我该如何解决这个缺陷?下面是服务器上的文件接收方法:
while (true) {
try {
bytesReceived = input.read(buffer);
} catch (IOException ex) {
Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
System.out.println("exception occured");
break;
}
System.out.println("received:" + bytesReceived);
try {
/* Write to the file */
wr.write(buffer, 0, bytesReceived);
} catch (IOException ex) {
Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
}
total_byte = total_byte + bytesReceived;
if (total_byte >= filesizeInt) {
break;
}
}
Run Code Online (Sandbox Code Playgroud) 当我通过以下代码重现 SHA2 哈希时:
MessageDigest digest = MessageDigest.getInstance("SHA-256");
digest.digest("A".getBytes("UTF-8"));
Run Code Online (Sandbox Code Playgroud)
它给了我一个字节数组,即: 85,-102,-22,-48,-126,100,-43,121,93,57,9,113,-116,-35,5,-85,-44,-107,114, -24,79,-27,85,-112,-18,-13,26,-120,-96,-113,-33,-3
但是当我通过 MySQL 重现相同的哈希时,它给了我一个字符串:5cfe2cddbb9940fb4d8505e25ea77e763a0077693dbb01b1a6aa94f2
如何转换 Java 的结果以便与 MySQL 的结果进行比较?