檔案寫入和讀取,加密解密,xml例

2021-07-15 23:54:30 字數 1710 閱讀 5068

using unityengine;

using system.collections;

using system.io;

using system;

using system.text;

using system.security.cryptography;

using system.xml.serialization;

using system.xml;

//檔案寫入讀取

public class fileoperation  

private static fileoperation instance;

public static fileoperation instance

}//寫檔案 

public static bool writefile_(string filepath, string writesomething)

//讀檔案 

public static string readfile_(string filepath)

else

return filedata;

}//寫檔案 加密

public static bool writefile_(string filepath,string writesomething,bool isencryption)

//讀檔案 解密

public static string readfile_(string filepath,bool isencryption)

else

return filedata;

}/// 加密方法  

/// 描述: 加密和解密採用相同的key,具體值自己填,但是必須為32位  

private static string encrypt(string toe)

/// 解密方法  

/// 描述: 加密和解密採用相同的key,具體值自己填,但是必須為32位  

private static string decrypt(string tod)

//xml儲存和讀取

public static object xmlwriteandread(string filepath,object obj)

//轉換資料型別

string s = serializeobject(obj,obj.gettype());

//建立xml檔案且寫入資料

writefile_(filepath, s);

//讀取資料

trycatch

return null;

}//資料物件轉換成xml字串

private static string serializeobject(object obj, type type)

/// xml字串轉換資料物件  

private static object deserializeobject(string pxmlizedstring, type ty)

//utf8位元組陣列轉字串  

private static string utf8bytearraytostring(byte characters)

//字串轉utf8位元組陣列  

private static byte stringtoutf8bytearray(string pxmlstring)

}

xml讀取和寫入

1 需要的命名空間 using system.collections.generic using system.io using system.text using system.xml 3 寫入後的xml檔案樣式 1神州俠侶 5045.55 tiger 以下 為自動建立序號時使用,若你的資料來源本...

XML檔案寫入與讀取

把這個東西做成通用方法 以後直接傳引數就可以了 很方便 以下為寫入 建立乙個新的guest節點並將它新增到根節點下 xmlelement parentnode xdoc.createelement guest xdoc.documentelement.prependchild parentnode ...

Go 讀取和寫入xml檔案示例

在學習go語言中,有關於go處理xml檔案的處理.在這裡記錄一下 在go語言中使用ioutil庫進行檔案的處理是特別方便的事情,這裡使用goland進行開發的示例 首先建立工程xml 如下圖所示 在main.go中對a.xml 的內容進行讀取 a.xml 的內容如下 zh 深圳寶安 yq 深圳福田 ...