帮我用c#创建txt文件 [英] help me out creating txt file using c#

查看:62
本文介绍了帮我用c#创建txt文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建文本文件,但不要对文件及其路径进行硬编码。我想用xml在Application.config中读取和写入文件。

所以请。帮助我。

I want to create text file but do not hard code the file and its path. I want use xml to read and write the file in Application.config.
So pls. help me out.

推荐答案

您可以使用<$ c $读取/写入 App.Config 文件c> ConfigurationManager 类,请参阅ConfigurationManager类[ ^ ]和以下 CodeProject 文章:阅读/用.NET 2.0编写App.Config文件 [ ^ ]。

创建和编写文本文件也有很好的解释,例如:如何:写入文本文件(C#编程指南) [ ^ ]。
You may read/write the App.Config file using the ConfigurationManager class, see "ConfigurationManager Class" at MSDN[^] and the following CodeProject article: "Read/Write App.Config File with .NET 2.0"[^].
Creating and writing a text file is also well explained, see, for instance: How to: "Write to a Text File (C# Programming Guide)"[^].


创建文本文件的简单代码:
Simple code to create a text file:
string path = "D:\\Log.txt";             //path and name of the text file
StreamWriter objStreamWriter = new StreamWriter(path);
objStreamWriter.Write("Hi Welcome. . ."); // sting to write on the text file
objStreamWriter.Close();


你会在CP上找到关于阅读(甚至编写)应用程序配置文件的文章:阅读/使用.NET 2.0编写App.Config文件 [ ^ ]。



创建文本文件的方法之一是使用方法 System.IO.File.CreateText(String path) [ ^ ]。



问候,

- Manfred
You'll find this article here on CP about reading (and even writing) the application's configuration file: Read/Write App.Config File with .NET 2.0[^].

One of the ways to create a text file is to use the method System.IO.File.CreateText(String path)[^].

Regards,
— Manfred


这篇关于帮我用c#创建txt文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆