我正在尝试通过 XML-RPC Base64 编码/解码将本地文件放到远程主机上。这对于二进制文件来说非常有效,但是当我尝试发送文本文件时,所有行结尾都被删除。为什么会出现这种情况?
在客户端,
my $buf;
my $encoded = '';
while (read($FILE, $buf, 60 * 57)) {
$encoded .= encode_base64($buf);
}
然后将其发送到我的 Redstone XML-RPC 服务器,该服务器接收它并将其写出:
// Create file
File file = new File(path);
file.createNewFile();
// Decode the encoded data sent over into bytes
byte[] bytes = Base64.decode(data.getBytes());
// Write them out to the file
FileOutputStream os = new FileOutputStream(file);
os.write(bytes);
os.flush();
os.close();
最佳答案
尝试以二进制方式设置$FILE,需要在open命令后指定:
open my $FILE, '<', 'the_file_name.extension';
binmode $FILE;
# your code ...
关于java - 序列化文本文件的新行丢失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7876790/