FileIO类 1. ClearMemory()2. ClearMemoryAsncy()3. AddBlankString(int length)4. Encode(string data)5. PingIP(string ip)6. Decode(string data)7. SetIniPath(string striniFilePath)8. ReadIniString(string section, string key)9. ReadIniInt(string section, string key)10. ReadIniDouble(string section, string key)11. Replace(string str, string oldStr, string newStr)12. WriteIniString(string section, string key, string val)13. DeleteSection(string Section)14. DeleteKey(string section, string key)15. GetSectionAllKeys(string Key)16. ConnTcp(string IPaddress, int Port, int WaitTime = 3)17. FileWrite(string path, string str, bool append = false, string encoding = "utf-8")18. GetSectionAllKeys(string Key)19. FileRead(string path, string encoding = "utf-8")20. FileCopy(string sourceFileName, string destFileName, bool overwrite = true)21. CreateFolder(string fileName = null, string filePath = null)22.FileToBytes(string path)23.BytesToFile(byte[] bytes, string saveFile)
FileIO类提供了对文件系统的操作方法。下面是各个方法的说明:
功能:清除内存中的缓存数据。
用法示例:
xxxxxxxxxx
FileIO.ClearMemory();
功能:异步清除内存中的缓存数据。
用法示例:
xxxxxxxxxx
await FileIO.ClearMemoryAsncy();
功能:在当前位置添加指定长度的空白字符串。
参数:length - 空白字符串的长度。
返回值:返回添加空白字符串后的结果。
用法示例:
xxxxxxxxxx
string result = FileIO.AddBlankString(5);
功能:对给定的字符串进行编码。
参数:data - 要编码的字符串。
返回值:返回编码后的字符串。
用法示例:
xxxxxxxxxx
string encodedData = FileIO.Encode("Hello, World!");
功能:检查给定的IP地址是否可通。
参数:ip - 要检查的IP地址。
返回值:如果IP地址可通,则返回true;否则返回false。
用法示例:
xxxxxxxxxx
bool isReachable = FileIO.PingIP("192.168.0.1");
功能:对给定的字符串进行解码。
参数:data - 要解码的字符串。
返回值:返回解码后的字符串。
用法示例:
xxxxxxxxxx
string decodedData = FileIO.Decode("SGVsbG8sIFdvcmxkIQ==");
功能:设置INI文件的路径。
参数:striniFilePath - INI文件的路径。
用法示例:
xxxxxxxxxx
FileIO.SetIniPath("/path/to/ini/file.ini");
功能:从指定的INI文件中读取指定section和key的值。
参数:section - INI文件中的section名称。
key - INI文件中的key名称。
返回值:返回读取到的值。
用法示例:
xxxxxxxxxx
string value = FileIO.ReadIniString("SectionName", "KeyName");
功能:从指定的INI文件中读取指定section和key的整数值。
参数:section - INI文件中的section名称。
key - INI文件中的key名称。
返回值:返回读取到的整数值。
用法示例:
xxxxxxxxxx
int intValue = FileIO.ReadIniInt("SectionName", "KeyName");
功能:从指定的INI文件中读取指定section和key的双精度浮点数值。
参数:
section - INI文件中的section名称。
key - INI文件中的key名称。
返回值:返回读取到的双精度浮点数值。
用法示例:
xxxxxxxxxx
double doubleValue = FileIO.ReadIniDouble("SectionName", "KeyName");
功能:在给定的字符串中替换所有的旧字符串为新字符串。
参数:str - 原始字符串。
oldStr - 要替换的旧字符串。
newStr - 替换成的新字符串。
返回值:返回替换后的字符串。
用法示例:
xxxxxxxxxx
string replacedString = FileIO.Replace("Hello, World!", "World", "Everyone");
功能:向指定的INI文件中写入指定section和key的值。
参数:section - INI文件中的section名称。
key - INI文件中的key名称。
val - 要写入的值。
用法示例:
xxxxxxxxxx
FileIO.WriteIniString("SectionName", "KeyName", "Value");
功能:删除指定的INI文件中的section。
参数:Section - 要删除的section名称。
用法示例:
xxxxxxxxxx
FileIO.DeleteSection("SectionName");
功能:删除指定的INI文件中的key。
参数:
section - INI文件中的section名称。
key - INI文件中的key名称。
用法示例:
xxxxxxxxxx
FileIO.DeleteKey("SectionName", "KeyName");
功能:获取指定INI文件中的所有key。
参数:Key - 要获取的key的前缀。
返回值:返回匹配到的所有key列表。
用法示例:
xxxxxxxxxx
List<string> keys = FileIO.GetSectionAllKeys("SectionName");
功能:建立TCP连接。
参数:
IPaddress - 目标IP地址。
Port - 目标端口号。
WaitTime - 连接超时时间(单位:秒)。
返回值:返回建立的TcpClient对象。
用法示例:
xxxxxxxxxx
TcpClient client = FileIO.ConnTcp("192.168.0.1", 8080, 5);
功能:将字符串写入文件。
参数:path - 文件路径。
str - 要写入的字符串。
append - 是否追加模式写入(默认为覆盖模式)。
encoding - 文件编码(默认为UTF-8)。
用法示例:
xxxxxxxxxx
FileIO.FileWrite("path/to/file.txt", "Hello, World!", true);
功能:获取指定目录中的所有文件。
参数:Key - 要获取的文件名的前缀。
返回值:返回匹配到的所有文件列表。
用法示例:
xxxxxxxxxx
List<string> files = FileIO.GetFiles("path/to/directory", "*.*");
功能:读取文件内容。
参数:
path - 文件路径。
encoding - 文件编码(默认为UTF-8)。
返回值:返回文件的内容。
用法示例:
xxxxxxxxxx
string content = FileIO.FileRead("path/to/file.txt");
功能:复制文件。
参数:
sourceFileName - 源文件路径。
destFileName - 目标文件路径。
overwrite - 是否覆盖已存在的文件(默认为覆盖模式)。
用法示例:
xxxxxxxxxx
FileIO.FileCopy("path/to/source/file.txt", "path/to/destination/file.txt");
功能:获取保存文件夹的路径。
参数:
fileName
(可选):保存文件夹名称,默认为空字符串。
filePath
(可选):保存文件夹的根路径,默认为空字符串。
返回值:返回保存文件夹的路径。
用法示例:
xxxxxxxxxx
CreateFolder("文件夹","D:\\")
功能:将指定文件转换为字节数组。
参数:
path
:要转换的文件的路径。
返回值:返回转换后的字节数组。
功能:将字节数组保存为文件。
参数:
bytes
:字节数组。
saveFile
:保存的文件名称
返回值:返回转换后的文件。