【问题标题】:Creating a file in Windows CE 5.0 in C#在 C# 中在 Windows CE 5.0 中创建文件
【发布时间】:2011-07-22 12:22:20
【问题描述】:

我使用的是 Windows CE 5.0 移动设备、Visual Studio 2008 和 Compact Framework 2.0

当我通过 VS 2008 执行应用程序时,该程序被复制到 Windows CE 5.0 设备内的文件夹中,并显示在其显示屏中。我想在那里创建一个文本文件。

这是我正在尝试的代码:

try
{
  TextWriter tw = new StreamWriter("date.txt");

  // write a line of text to the file
  tw.WriteLine(DateTime.Now);

  // close the stream
  tw.Close();
  label1.Text = "file created";
}
catch (Exception ex)
{
  label1.Text = ex.Message;
}

没有错误信息,但是文件没有创建,在我的电脑(项目所在的地方)和Windows CE 5.0终端设备(每次都自动复制程序正在调试的地方)都没有。

知道我做错了什么吗?

【问题讨论】:

    标签: c# visual-studio-2008 file-io compact-framework windows-ce


    【解决方案1】:
    private void saveFile()
    {
        // If the File does not exist, create it!
    
        if (! File.Exists("date.txt") ) // may have to specify path here!
        {
            // may have to specify path here!
            File.Create("date.txt").Close();
        }
    
        // may have to specify path here!
        StreamWriter swFile =
                     new StreamWriter(
                        new FileStream("date.txt",
                                       FileMode.Truncate),
                        Encoding.ASCII);
    
        swFile.Write("some text");
    
        swFile.Close();
    
    }
    

    【讨论】:

      【解决方案2】:
      TextWriter twFile = new StreamWriter (StockFileLoc);
      twFile.Write (sbStock.ToString ());
      twFile.Flush ();
      twFile.Close ();
      

      我使用 StringBuilder 来创建文件,但是一个普通的字符串就足够了,StockFileLoc 包含文件位置

      StockFileLoc = @"\folder\file.txt";
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-12-01
        • 1970-01-01
        • 2011-09-28
        • 2015-10-04
        • 2012-01-21
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多