public class DuQu : MonoBehaviour
void ReadFile()
{
string path = Application.dataPath + "/File/a.txt";//文件路径
string sl = File.ReadAllText(path);
print(sl);
string[] s2 = File.ReadAllLines(path);
foreach (var item in s2)
{
print(item);
}
//读取二进制文件
byte[] s3 = File.ReadAllBytes(Application.dataPath + "File/bg.png");
string s4 = Encoding.UTF8.GetString(s3);
print(s4);
}
void WriteFile()
{
string path = Application.dataPath + "/File/b.txt";
string s1 = "Hello World";
File.WriteAllText(path, s1);
string[] s2 = { "D", "D", "D" };
File.WriteAllLines(path, s2);
string s3 = "D";
byte[] s4 = Encoding.UTF8.GetBytes(s3);
File.AppendAllText(path, "/nD");
}
void Get()
{
FileInfo f = new FileInfo(Application.dataPath + "/File/a.txt");
print(f.Name);
print(f.Length);
print(f.FullName);
print(f.DirectoryName);
print(f.IsReadOnly);//只读属性
if (!f.Exists)//如果不存在
{
f.Create();//创建
}
f.MoveTo(Application.dataPath + "/File/c.txt");//重命名
}
}