判断文件是否存在,不存在则创建;
if (!File.Exists(filename))
{
FileStream file = File.Create(filename);
file.Close();
}
文件尾添加数据;
using (FileStream filedata = new FileStream(filename, FileMode.Open, FileAccess.ReadWrite))
{
filedata.Seek(0, SeekOrigin.End);
filedata.Write(Data, 0, Data.Length);
filedata.Flush();
filedata.Close();
}
文件读取数据;
FileStream filedata = new FileStream(filename, FileMode.Open, FileAccess.ReadWrite);
public byte[] ReadFileData(FileStream file, int offset, int count)
{
byte[] buf = new byte[count];
file.Seek(offset, SeekOrigin.Begin);
file.Read(buf, 0, count);
file.Close();
return buf;
}
路径操作;
创建路径;
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
遍历路径;
public void ShowDirFiles()
{
DirectoryInfo dir = new DirectoryInfo(path);
foreach (DirectoryInfo d in dir.GetDirectories())
{
Console.WriteLine(d.Name);
}
foreach (FileInfo f in dir.GetFiles(“*.txt”))
{
Console.WriteLine(f.Name);
f.Delete();
}
}