//基础操作
string path=Application.dataPath+"/Files/a.txt";//文件路径
FileInfo f = new FileInfo(path);
print(f.Name);//文件名
print(f.Length);//文件内容长度
print(f.Exists);//文件是否存在
print(f.DirectoryName);
print(f.FullName);//文件全名
print(f.IsReadOnly);//是否为只读
if (!f.Exists)//文件不存在
{
f.Create();//创建新文件
}
f.MoveTo(Application.dataPath +"/File/b.txt");//重命名
//读写文件
File.ReadAllText(path);//读取所有行,不换行
File.ReadAllLines(path);//读取所有行,换行
byte[] s1=File.ReadAllBytes(Application.dataPath +"/File/图片.png");//读取二进制
string s2=Encoding.Default.GetString(bytes);
File.WriteAllText(path,"内容");//写入一行
string[] s3={" "," "};
File.WriteAllLines(path,s3);//写入多行
string s4 = "32yghh";
byte[] s5 = Encoding.UTF8.GetBytes(s4);
File.WriteAllBytes(Application.dataPath +"/File/baby.txt",s5);//写入一行字节