作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我已将一个文本文件添加到 Windows 窗体应用程序中并尝试访问该文件。
这是我的代码..
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
System.String s = Application.StartupPath+"/Licence.txt";
System.IO.FileInfo fi = new System.IO.FileInfo(s);
if (fi.Exists)
{
if (fi.Length == 0)
{
Application.Run(new Form1());
}
}
}
Licence.txt 存在于我的项目文件夹中,但每次 (fi.Exists) 仅变为 false,并且程序退出流程而不显示 Form1() 窗口。请帮我。提前致谢..
最佳答案
使用这个:
string s = Path.Combine(
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
"Licence.txt");
不要尝试手动组合路径,因为您必须处理路径定界符...使用内置函数要好得多!
最后记得在项目中的 License.txt 文件上设置 Copy to Output
属性。
关于c# - 如何在 Windows 窗体应用程序中访问文本文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20467815/
我是一名优秀的程序员,十分优秀!