简体   繁体   English

StreamWriter的用法

[英]Usage of StreamWriter

I'm using the following code to open a file and then trying to write something to it: 我正在使用以下代码打开文件,然后尝试向其中写入一些内容:

public partial class MainWindow : Window
{
    StreamWriter file = null;
    public MainWindow()
    {
        InitializeComponent();
        using (file = new StreamWriter("../data/floorPlane.txt", true))
        {
            file.WriteLine("x \t y \t z \t w \n");
        }
    }
}

But it always gives the following error: 但是它总是会出现以下错误:

A first chance exception of type 'System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll PresentationFramework.dll中发生类型为'System.Windows.Markup.XamlParseException'的第一次机会异常

Additional information: 'The invocation of the constructor on type 'SkeletalViewer.MainWindow' that matches the specified binding constraints threw an exception. 附加信息:“对类型为'SkeletalViewer.MainWindow'的构造函数的调用与指定的绑定约束匹配,引发了异常。

I'm totally new to c#. 我是C#的新手。 Maybe the question is kindof stupid. 也许这个问题有点愚蠢。

Thanks, 谢谢,

First, check the inner exception to see what you are actually messing up. 首先,检查内部异常,看看您实际上是在搞什么。 Then, if the answer is still not apparent, compare your code to the sample found at this MSDN article: http://msdn.microsoft.com/en-us/library/vstudio/system.io.streamwriter 然后,如果答案仍然不明显,请将您的代码与在此MSDN文章中找到的示例进行比较: http : //msdn.microsoft.com/zh-cn/library/vstudio/system.io.streamwriter

this exception is caught many times. 这个异常被多次捕获。 You can press ctrl+alt+E to check all exception and than you can find real exception. 您可以按ctrl + alt + E 检查所有异常,然后才能找到真正的异常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM