1 void Start()
2 {
3 CreateDirectory();
4 CreateFile();
5 }
6
7 //平台的路径(封装起来的一个属性,这不是一个方法)
8 public string path
9 {
10 get
11 {
12 //pc,ios //android :jar:file//
13 //Application.persistentDataPath: C:/Users/电脑的用户名/AppData/LocalLow/CompanyName/ProductName
14 return Application.persistentDataPath + "/CacheDirectory/";
15 }
16 }
17
18 //创建目录
19 void CreateDirectory()
20 {
21 //if (!File.Exists(path + "a.txt")) //判断某个目录下是否存在某个文件
22 if (!Directory.Exists(path)) //判断是否存在某个文件夹
23 {
24 //File.Create(path + "picture.txt"); 。
25 Directory.CreateDirectory(path); //创建文件夹
26 print("CacheDirectory 创建成功!");
27 }
28 else
29 {
30 print("CacheDirectory 已经存在!");
31 }
32 }
33
34 //创建文件
35 void CreateFile()
36 {
37 //如果不存在这个文件就创建
38 if (!File.Exists(path + "123.txt"))
39 {
40 //在某个文件夹里面创建 .txt/.jpg 等文件,创建不了文件夹,没有path这个文件夹的话就创建不了(会报错)
41 File.Create(path + "123.txt");
42 print("123.txt 创建成功!");
43 }
44 else
45 {
46 print("123.txt 已经存在!");
47 }
48
49 if (!File.Exists(path + "picture.jpg"))
50 {
51 //在某个文件夹里面创建 .txt/.jpg 等文件,创建不了文件夹,没有path这个文件夹的话就创建不了(会报错)
52 File.Create(path + "picture.jpg");
53 print("picture.jpg 创建成功!");
54 }
55 else
56 {
57 print("picture.jpg 已经存在!");
58 }
59 }