Windows程序在E:\MyForm文件夹下运行能不能E:\NewFile文件夹下面创建一个文件(如txt)。如果NewFile文件夹不存在,就创建他。
解决方案 »
- 开发软件 用什么数据库最合适
- Ascii <--> Hex
- WPF的简单问题
- (100分)自定义控件的问题(类似于浏览器导航栏)
- C#.net 请教使用URL传递参数问题
- this指针的问题,高手指点
- 那位兄弟有FCKeditor的.net版
- MySQL.OleDb Provider 出现的问题 ,是不是它的bug。
- 写C#除了vs.net外,其他还有那些比较好的编辑器,最好支持所见所得的。
- 请教一个不太难的问题?
- 一个问题(大致是关于监听目录),不知如何下手,敬请各位提点建设性的意见,秀秀你们的功力,不胜感激!
- 请教高人难题!C# 导出 Excel ,如何单元格 设置 格式(以数据流的形式写出Excel)急!!
Creates or overwrites the specified file, specifying a buffer size and a FileOptions value that describes how to create or overwrite the file.
………………if(!File.Exsit(_FilePath))
{
File.Creat(_FilePath);
}
{
Directory.Create(path);
}
//do
try
{
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
}
hoho 更正 更正 二师兄的也没写对 面壁10分钟
{
Directory.CreateDirectory(dir);
}上面的程序是在E盘上生成了两个文件夹(Fi*和Test.txt),
并没有生成文本文件啊?
{
File.Creat(dir);
}
using System.IO;
using System.Text;class Test
{
public static void Main()
{
string path = @"c:\temp\MyTest.txt"; try
{ // Delete the file if it exists.
if (File.Exists(path))
{
// Note that no lock is put on the
// file and the possibliity exists
// that another process could do
// something with it between
// the calls to Exists and Delete.
File.Delete(path);
} // Create the file.
using (FileStream fs = File.Create(path))
{
Byte[] info = new UTF8Encoding(true).GetBytes("This is some text in the file.");
// Add some information to the file.
fs.Write(info, 0, info.Length);
} // Open the stream and read it back.
using (StreamReader sr = File.OpenText(path))
{
string s = "";
while ((s = sr.ReadLine()) != null)
{
Console.WriteLine(s);
}
}
} catch (Exception Ex)
{
Console.WriteLine(Ex.ToString());
}
}
}
CSDN使人变懒不过能让人少走弯路