按名称查找文本文件 [英] Find text file by name

查看:67
本文介绍了按名称查找文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Window应用程序中创建新的文本文件.我正在读取和写入来自"C:\\ test.txt"的文本文件.现在我想在第一次写入或读取此文本文件时要检查该文件是否已经在C驱动器中,如果没有,则创建,如果是,则创建我的进程.
文件和路径始终固定不变.
而且我还希望,如果文件已经在C驱动器中,则检查任何数据是否存在文本文件或为空.

I want to create new text file in my Window application.I am read and write text file from "C:\\test.txt".Now i want that when i write or read this text file first i want to check is this file already in C drive if not then create if yes then do my process.
File and path always fix not change.
And i also want that if file is already in C drive then check any data is there is text file or empty.

推荐答案

您可以使用File.Exists()检查功能

You can use the File.Exists() function to check

if(System.IO.File.Exists("C:\\test.txt"))
{
  // exists. Open
}
else
{
  // does not exist. Create
}


这篇关于按名称查找文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆