c# - 获取记事本的值并将其放入 c# 字符串中?

标签 c# file notepad

记事本:

Hello world!

我如何将它放入 C# 并将其转换为字符串......?

到目前为止,我正在获取记事本的路径。

 string notepad = @"c:\oasis\B1.text"; //this must be Hello world

请告诉我..我对此不熟悉.. tnx

最佳答案

您可以使用 File.ReadAllText() 方法读取文本:

    public static void Main()
    {
        string path = @"c:\oasis\B1.txt";

        try {

            // Open the file to read from.
            string readText = System.IO.File.ReadAllText(path);
            Console.WriteLine(readText);

        }
        catch (System.IO.FileNotFoundException fnfe) {
            // Handle file not found.  
        }

    }

关于c# - 获取记事本的值并将其放入 c# 字符串中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6220318/

相关文章:

python - 从文件末尾寻找抛出不受支持的异常

java - 一个java程序 "type"可以变成另一个windows程序如记事本吗

java - Java 中受密码保护的记事本问题

c# - 将列表数据添加到文本文件

python - 覆盖以前提取的文件而不是创建新文件

json - vue上传本地json文件

c# - Unity 示例项目 "Roll a Ball"无法在 iPad 上运行(球不移动)?

c# - 绑定(bind)到 UserControl "Failed to assign to property"错误 (Windows 8)

c# - 如何检测: scrolling - up or down?

c# - 如何从 Postman 将 XML 传递到 ASP.Net Core 中的 Web API