谁能解这个以216进制解密

xml解析解析二进制-转
在xml中,所有的数据都是以文本的形式来显示,但是二进制数据不能直接以文本格式来表示,那xml又是怎么处理二进制数据的呢?下面就来探讨一下。
为了简单和通用性,xml被设计成了以文本的格式来表示数据。在xml中,所有的数据都是以文本的格式来存储,二进制数据也不例外。在xml中,二进制数据也要被编码成文本的格式,发送到目的方。目的方接收到这个文本二进制数据以后,再以相同的解码程序解成相应的二进制数据,当然数据原来的格式,名称等辅助信息一定要当作相关信息一起发送。一般二进制数据编码成BASE64格式,它的优点是容易易于编码和解码,缺点是比纯的二进制多占用33%的存储空间。
下面是具体的程序实现:
contentType="text/ charset=gb2312"
import="java.io.*" %&
String ret=new
InputStream in=new
FileInputStream("c:\\aaa.doc");
byte[] bytes=new
byte[in.available()];
in.read(bytes);
sun.misc.BASE64Encoder().encode(bytes); //具体的编码方法
in.close();
catch(FileNotFoundException e)
e.printStackTrace();
catch(java.io.IOException ex)
ex.printStackTrace();
ret就是最后的结果,编码以后就可以用标准的xml方式发送了。发送到目的方以后,还要对数据进行相应的解码,才能得到原来的二进制文件,解码的代码如下:
contentType="text/ charset=gb2312"
import="java.io.*" %&
byte[] bytes = new
sun.misc.BASE64Decoder().decodeBuffer(ret);
java.io.ByteArrayInputStream
inStream=new java.io.ByteArrayInputStream(bytes);
byte[] buffer =new
byte[1444];
FileOutputStream fs=new
FileOutputStream( "d:\\aaa.doc");
int bytesum=0;
int byteread=0;
((byteread=inStream.read(buffer))!=-1) {
fs.write(buffer,0,byteread);
BASE64可以处理不太大的数据,如果要移动大量的数据,且要考虑空间/时间效率时,要采用其他的替代方法。
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。#region 将本地压缩文件转换为Base64编码
/// &summary&
/// 将本地压缩文件转换为Base64编码
/// &/summary&
/// &returns&&/returns&
public string ReturnBase64Code()
//从服务器获取到的文件路径
string ys_filePath =
rootDirectoryPath + @"\hx.zip";
//将压缩文件转换为二进制
using (FileStream fs = new FileStream(ys_filePath, FileMode.Open))
byte[] bytes = new byte[fs.Length];
int count = Convert.ToInt32(fs.Length);
fs.Read(bytes, 0, count);
fs.Close();
//将二进制转为为base64
return Convert.ToBase64String(bytes);
#endregion
#region 直接删除指定目录下的所有文件及文件夹(保留目录)
/// &summary&
/// 直接删除指定目录下的所有文件及文件夹(保留目录)
/// &/summary&
/// &param name="strPath"&文件夹路径&/param&
/// &returns&执行结果&/returns&
public bool DeleteDir(string strPath)&&&&&
try&&&&&&&&&
strPath = @strPath.Trim().ToString();//&清除空格&
if (System.IO.Directory.Exists(strPath))&&//&判断文件夹是否存在&&&&&&&&&&&&
//&获得文件夹数组&
string[]&strDirs&=&System.IO.Directory.GetDirectories(strPath);&//&获得文件数组&
string[]&strFiles&=&System.IO.Directory.GetFiles(strPath);&//&遍历所有子文件夹&
foreach&(string strFile in strFiles)&&&&&&&&&&&&&&&&&
//&删除文件夹&
System.IO.File.Delete(strFile);&&&&&&&&&&&&&&&&&
//&遍历所有文件&
foreach&(string strdir in strDirs)&&&&&&&&&&&&&&&&&
//&删除文件&
System.IO.Directory.Delete(strdir,&true);&&&&&&&&&&&&&&&&&
}&&&&&&&&&&&&&
return true;&&&&&&&&&&&&&&&&&&&&&
catch&(Exception Exp)&//&异常处理&&&&&&&&&
System.Diagnostics.Debug.Write(Exp.Message.ToString());&//&异常信息&
return false;&&&&&&&&&
#endregion
#region 定时下载广告文件
public void theout(object source, System.Timers.ElapsedEventArgs e)
string str = ReturnBase64Code();//将二进制转为为base64
byte[] outputb = Convert.FromBase64String(str);//将base64编码转换为二进制
//将二进制转换为压缩文件
string path = rootDirectoryPath + @"\new_hx.zip";//压缩文件的地址
File.WriteAllBytes(path, outputb);
//删除广告目录下已经存在的文件
if (Directory.Exists(filePath))
DeleteDir(filePath);
//解压文件
bool result = bonkerZip.UnZipFile(path, filePath); //
DeCompressionZip
if (!result)
ErrorLog.WriteErrorLog(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + "广告文件解压失败,失败原因:"+bonkerZip.errorMsg);
webBrowser1.Navigate(filePath+@"\index.html");
#endregion
1 public class BonkerZip
/// &summary&
/// 存放待压缩的文件的绝对路径
/// &/summary&
private List&string& AbsolutePaths { set; get; }
public string errorMsg { set; get; }
public BonkerZip()
errorMsg = "";
AbsolutePaths = new List&string&();
/// &summary&
/// 添加压缩文件
/// &/summary&
/// &param name="_fileAbsolutePath"&文件的绝对路径&/param&
public void AddFile(string _fileAbsolutePath)
AbsolutePaths.Add(_fileAbsolutePath);
/// &summary&
/// 压缩文件或者文件夹
/// &/summary&
/// &param name="_depositPath"&压缩后文件的存放路径
如C:\\windows\abc.zip&/param&
/// &returns&&/returns&
public bool CompressionZip(string _depositPath)
bool result = true;
FileStream fs = null;
ZipOutputStream ComStream = new ZipOutputStream(File.Create(_depositPath));
ComStream.SetLevel(9);
//压缩等级
foreach (string path in AbsolutePaths)
//如果是目录
if (Directory.Exists(path))
ZipFloder(path, ComStream, path);
else if (File.Exists(path))//如果是文件
fs = File.OpenRead(path);
byte[] bts = new byte[fs.Length];
fs.Read(bts, 0, bts.Length);
ZipEntry ze = new ZipEntry(new FileInfo(path).Name);
ComStream.PutNextEntry(ze);
//为压缩文件流提供一个容器
ComStream.Write(bts, 0, bts.Length);
//写入字节
ComStream.Finish(); // 结束压缩
ComStream.Close();
catch (Exception ex)
if (fs != null)
fs.Close();
errorMsg = ex.M
result = false;
//压缩文件夹
private void ZipFloder(string _OfloderPath, ZipOutputStream zos, string _floderPath)
foreach (FileSystemInfo item in new DirectoryInfo(_floderPath).GetFileSystemInfos())
if (Directory.Exists(item.FullName))
ZipFloder(_OfloderPath, zos, item.FullName);
else if (File.Exists(item.FullName))//如果是文件
DirectoryInfo ODir = new DirectoryInfo(_OfloderPath);
string fullName2 = new FileInfo(item.FullName).FullN
string path = ODir.Name + fullName2.Substring(ODir.FullName.Length, fullName2.Length - ODir.FullName.Length);//获取相对目录
FileStream fs = File.OpenRead(fullName2);
byte[] bts = new byte[fs.Length];
fs.Read(bts, 0, bts.Length);
ZipEntry ze = new ZipEntry(path);
zos.PutNextEntry(ze);
//为压缩文件流提供一个容器
zos.Write(bts, 0, bts.Length);
//写入字节
/// &summary&
/// &/summary&
/// &param name="_depositPath"&压缩文件路径&/param&
/// &param name="_floderPath"&解压的路径&/param&
/// &returns&&/returns&
public bool DeCompressionZip(string _depositPath, string _floderPath)
bool result = true;
FileStream fs=null;
using (ZipInputStream InpStream = new ZipInputStream(File.OpenRead(_depositPath)))
ZipEntry ze = InpStream.GetNextEntry();//获取压缩文件中的每一个文件
Directory.CreateDirectory(_floderPath);//创建解压文件夹
while (ze != null)//如果解压完ze则是null
if (ze.IsFile)//压缩zipINputStream里面存的都是文件。带文件夹的文件名字是文件夹\\文件名
string[] strs = ze.Name.Split('\\');//如果文件名中包含&\\&则表明有文件夹
if (strs.Length & 1)
//两层循环用于一层一层创建文件夹
for (int i = 0; i & strs.Length - 1; i++)
string floderPath = _floderP
for (int j = 0; j & j++)
floderPath = floderPath + "\\" + strs[j];
floderPath = floderPath + "\\" + strs[i];
Directory.CreateDirectory(floderPath);
fs = new FileStream(_floderPath + "\\" + ze.Name, FileMode.OpenOrCreate, FileAccess.Write);//创建文件
//循环读取文件到文件流中
while (true)
byte[] bts = new byte[1024];
int i = InpStream.Read(bts, 0, bts.Length);
if (i & 0)
fs.Write(bts, 0, i);
fs.Flush();
fs.Close();
ze = InpStream.GetNextEntry();
catch (Exception ex)
if (fs != null)
fs.Close();
errorMsg = ex.M
result = false;
if (fs != null)
fs.Close();
fs.Dispose();
/// &summary&
/// 功能:解压zip格式的文件。
/// &/summary&
/// &param name="zipFilePath"&压缩文件路径&/param&
/// &param name="unZipDir"&解压文件存放路径,为空时默认与压缩文件同一级目录下,跟压缩文件同名的文件夹&/param&
/// &param name="err"&出错信息&/param&
/// &returns&解压是否成功&/returns&
public bool UnZipFile(string zipFilePath, string unZipDir)// , out string err
// err = "";
if (zipFilePath == string.Empty)
//err = "压缩文件不能为空!";
return false;
if (!File.Exists(zipFilePath))
//err = "压缩文件不存在!";
return false;
//解压文件夹为空时默认与压缩文件同一级目录下,跟压缩文件同名的文件夹
if (unZipDir == string.Empty)
unZipDir = zipFilePath.Replace(Path.GetFileName(zipFilePath), Path.GetFileNameWithoutExtension(zipFilePath));
if (!unZipDir.EndsWith("\\"))
unZipDir += "\\";
if (!Directory.Exists(unZipDir))
Directory.CreateDirectory(unZipDir);
using (ZipInputStream s = new ZipInputStream(File.OpenRead(zipFilePath.ToLower())))
ZipEntry theE
while ((theEntry = s.GetNextEntry()) != null)
string directoryName = Path.GetDirectoryName(theEntry.Name);
string fileName = Path.GetFileName(theEntry.Name);
if (directoryName.Length & 0)
Directory.CreateDirectory(unZipDir + directoryName);
if (!directoryName.EndsWith("\\"))
directoryName += "\\";
if (fileName != String.Empty)
using (FileStream streamWriter = File.Create(unZipDir + theEntry.Name))
int size = 2048;
byte[] data = new byte[2048];
while (true)
size = s.Read(data, 0, data.Length);
if (size & 0)
streamWriter.Write(data, 0, size);
catch (Exception ex)
//err = ex.M
return false;
return true;
}//解压结束
阅读(...) 评论()新手园地& & & 硬件问题Linux系统管理Linux网络问题Linux环境编程Linux桌面系统国产LinuxBSD& & & BSD文档中心AIX& & & 新手入门& & & AIX文档中心& & & 资源下载& & & Power高级应用& & & IBM存储AS400Solaris& & & Solaris文档中心HP-UX& & & HP文档中心SCO UNIX& & & SCO文档中心互操作专区IRIXTru64 UNIXMac OS X门户网站运维集群和高可用服务器应用监控和防护虚拟化技术架构设计行业应用和管理服务器及硬件技术& & & 服务器资源下载云计算& & & 云计算文档中心& & & 云计算业界& & & 云计算资源下载存储备份& & & 存储文档中心& & & 存储业界& & & 存储资源下载& & & Symantec技术交流区安全技术网络技术& & & 网络技术文档中心C/C++& & & GUI编程& & & Functional编程内核源码& & & 内核问题移动开发& & & 移动开发技术资料ShellPerlJava& & & Java文档中心PHP& & & php文档中心Python& & & Python文档中心RubyCPU与编译器嵌入式开发驱动开发Web开发VoIP开发技术MySQL& & & MySQL文档中心SybaseOraclePostgreSQLDB2Informix数据仓库与数据挖掘NoSQL技术IT业界新闻与评论IT职业生涯& & & 猎头招聘IT图书与评论& & & CU技术图书大系& & & Linux书友会二手交易下载共享Linux文档专区IT培训与认证& & & 培训交流& & & 认证培训清茶斋投资理财运动地带快乐数码摄影& & & 摄影器材& & & 摄影比赛专区IT爱车族旅游天下站务交流版主会议室博客SNS站务交流区CU活动专区& & & Power活动专区& & & 拍卖交流区频道交流区
丰衣足食, 积分 574, 距离下一级还需 426 积分
论坛徽章:1
现在我有个服务程序(c/c++编写的),以daemon形式运行在后台。 我要更新服务时,必须先杀死进程,然后才能将新的程序文件覆盖过来,否则会提示Text File Busy.
我记得以前工作的公司里有代码可以在服务启动后解除对二进制文件的占用,这样程序不需要杀死就可以更新。
&&nbsp|&&nbsp&&nbsp|&&nbsp&&nbsp|&&nbsp&&nbsp|&&nbsp
小富即安, 积分 2177, 距离下一级还需 2823 积分
论坛徽章:0
用动态库.so更新
论坛徽章:39
先rm原来的,或者先把原来的mv到别的地方,再复制新的过来。
你只是不能“改写”这个文件,但你可以删除/移动/改名/...
巨富豪门, 积分 23880, 距离下一级还需 16120 积分
论坛徽章:58
& & 这个也是对有的OS也不行, 我记得我这样干过, 出了莫明的错误。
大约那个SB的OS(忘记了是Xnix还是Win了),在交换页面的把新的内容给Load进去了。
论坛徽章:39
Windows就是你说的SB OS,连动都不让你动。
丰衣足食, 积分 804, 距离下一级还需 196 积分
论坛徽章:1
有一种叫做热补丁的东西!
丰衣足食, 积分 574, 距离下一级还需 426 积分
论坛徽章:1
非常感谢各位的回复,&&mv掉可以满足我的需求了。}

我要回帖

更多关于 16进制解密 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信