c# - System.IO.DirectoryNotFoundException 找不到路由的一部分
问题描述
我想.txt
通过在项目文件夹中调用文件来读取和解析文件。这是读取的代码
string[] line = { };
string route = @"~\\file\\" + ".text";
line = System.IO.File.ReadAllLines(route);
当它尝试从文件中读取所有行时出现错误,它转到另一条路线,如下所示:
C:\Program Files (x86)\IIS Express\~\Files\.text
该项目位于D盘。
解决方案
string route = Server.MapPath(@"~\\file\\myfile.txt");
string[] line = System.IO.File.ReadAllLines(route);
推荐阅读
- api - 有没有办法通过代码更改 Redragon 产品的 RGB 设置?
- javascript - 如何从预测数据中获取映射数组中显示的温度数据以及一周中的所有日期?
- python - TensorFlow 会利用 GPU 进行预测分析吗?
- node.js - 使用 localhost 节点项目访问服务器上的数据库
- javascript - 第二个案例在满足条件后运行,带有 JS 开关案例
- python - vscode 中的 Jupyter Notebook 问题(所选解释器中未安装内核规范模块)
- python - UUID 可以用作用户将使用的跟踪号吗?
- java - 添加 OnclickListener 后,我的 Android 应用程序崩溃
- c# - 如果帐户过期,则强制用户注销
- mongodb - 在 Mongoose 上显示带有参数的对象列表