【问题标题】:File not Found exception when file is actually a resource文件实际上是资源时未找到文件异常
【发布时间】:2012-12-15 15:50:37
【问题描述】:

请朋友们检查一下这段代码并告诉我为什么我会得到FileNotFoundExceptionPathIsIllegal 异常...??

    void AddSearchTermLog(String term)
        {
            String data = File.ReadAllText(global::BenisImageDownloader.Properties.Resources.SearchTerms);
            if (data != String.Empty)
            {
                String temp = String.Empty;
                for (int i = 0; i < data.Length; i++)
                {
                    if (data[i] == (char)Keys.Enter)
                    {
                        if (temp == term)
                            return;
                        temp = String.Empty;
                    }
                    else
                        temp += data[i];
                }
            }
            File.AppendAllText(global::BenisImageDownloader.Properties.Resources.SearchTerms, term + Environment.NewLine);
        }

如果我做错了什么,请用正确的方法纠正我..

【问题讨论】:

    标签: c# file resources filenotfoundexception


    【解决方案1】:

    File.ReadAllText() 方法将string 作为您尝试打开、读取和关闭文件的参数。从 MSDN 中查看。

    我不这么认为global::BenisImageDownloader.Properties.Resources.SearchTermsstring

    【讨论】:

    • 但它是一个文件作为资源,那么如何操作它的添加和删除..??有没有别的办法..???
    • 我不知道,但如果你使用ReadAllText(),你应该使用path的字符串参数。
    • 但是这个东西没有返回任何语法或不适当的隐式类型转换错误,如果我们使用图片文件而不是图片框控件或图像对象的资源中的文本文件,它也可以正常工作。那为什么不使用简单的 ReadAllText() 方法...??如果你从我这边来看,这是一个真正的问题......
    猜你喜欢
    • 1970-01-01
    • 2013-08-27
    • 2020-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-29
    • 2019-06-26
    相关资源
    最近更新 更多