• C# IO流 File.Exists,Directory.Exists, File.Create,Directory.CreateDirectory


     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     }
  • 相关阅读:
    POJ 1466 Girls and Boys 黑白染色 + 二分匹配 (最大独立集) 好题
    POJ2226 Muddy Fields 二分匹配 最小顶点覆盖 好题
    POJ 2195 Going Home 最小费用流 裸题
    POJ 3368 Frequent values RMQ 训练指南 好题
    POJ 3187 杨辉三角+枚举排列 好题
    POJ 2393 贪心 简单题
    系统监控
    系统的初始化和服务
    vi与vim
    正文处理命令及tar命令
  • 原文地址:https://www.cnblogs.com/Peng18233754457/p/7895003.html
Copyright © 2020-2023  润新知