C# 文件操作函数 创建文件 判断存在
作者:秦风 时间:2023-08-12 15:14:51
文件创建:
File.Create(Application.StartupPath + "\\AlarmSet.txt");//创建该文件
System.IO.Path.GetFileName(filePath) //返回带扩展名的文件名
System.IO.Path.GetFileNameWithoutExtension(filePath) //返回不带扩展名的文件名
System.IO.Path.GetDirectoryName(filePath) //返回文件所在目录
文件存在:
File.Exists(Application.StartupPath + "\\AlarmSet.txt")
System.IO.DirectoryInfo info = new System.IO.DirectoryInfo(Application.StartupPath + "\\AlarmSet.txt");
MessageBox.Show(info.Exists.ToString());
是不是很简单,但有时候我们可能对GetFileNameWithoutExtension或GetDirectoryName这样的函数,感觉比较陌生,以前还总傻傻的自己写函数实现,原来就一行代码搞定啊~
标签:C#,文件操作
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
c#中SAPI使用总结——SpVoice的使用方法
2022-02-20 09:50:07
Spring框架基于注解开发CRUD详解
2021-08-04 03:39:03
![](https://img.aspxhome.com/file/2023/7/111447_0s.jpg)
C# Volatile的具体使用
2023-11-21 11:14:50
![](https://img.aspxhome.com/file/2023/0/71740_0s.png)
java控制台输出图书馆管理系统
2022-06-13 01:29:29
![](https://img.aspxhome.com/file/2023/4/61284_0s.jpg)
C++ 前置声明详解及实例
2023-02-28 10:39:46
使用游长编码对字符串压缩 Run Length编码示例
2022-02-18 06:58:51
C#巧用DateTime预设可选的日期范围(如本年度、本季度、本月等)
2022-09-19 11:06:41
![](https://img.aspxhome.com/file/2023/2/125992_0s.gif)
在当前Activity之上创建悬浮view之WindowManager悬浮窗效果
2023-02-09 21:02:12
Android自定义view实现仿抖音点赞效果
2021-11-04 11:58:19
![](https://img.aspxhome.com/file/2023/9/138949_0s.gif)
android使用handlerthread创建线程示例
2023-07-05 17:29:57
Java编程实现对象克隆(复制)代码详解
2023-02-13 10:12:31
![](https://img.aspxhome.com/file/2023/1/91071_0s.png)
Spring Boot缓存实战之Redis 设置有效时间和自动刷新缓存功能(时间支持在配置文件中配置)
2023-11-11 01:57:18
![](https://img.aspxhome.com/file/2023/3/59053_0s.png)
C#使用timer实现的简单闹钟程序
2023-07-30 00:24:28
C#高级静态语言效率利器之泛型详解
2023-01-24 09:18:02
C# 获取动态key的json对象的值案例
2023-03-03 22:02:08
MyBatis ofType和javaType的区别说明
2021-09-10 22:56:43
javaweb购物车案列学习开发
2021-10-28 13:30:26
![](https://img.aspxhome.com/file/2023/3/113463_0s.jpg)
Android嵌套滚动NestedScroll的实现了解一下
2022-09-10 13:48:57
![](https://img.aspxhome.com/file/2023/5/101825_0s.gif)
java和c#使用hessian通信的方法
2021-12-12 22:03:46
![](https://img.aspxhome.com/file/2023/7/68497_0s.png)
Java实现替换PDF中的字体功能
2023-10-04 13:24:17
![](https://img.aspxhome.com/file/2023/0/94320_0s.jpg)