using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Web.HttpContext.Current.Server.MapPath; namespace 追加文件删除文件
{
class Program
{
static void Main(string[] args)
{
// C#追加文件
StreamWriter sw = File.AppendText(Server.MapPath(".") + "\\myText.txt"); //这里有问题???
sw.WriteLine("追逐理想");
sw.WriteLine("kzlll");
sw.WriteLine(".NET笔记");
sw.Flush();
sw.Close(); }
}
}麻烦大家给我看看啊,哪里有问题,命名空间还是server.mappath那里有问题,谢谢了
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Web.HttpContext.Current.Server.MapPath; namespace 追加文件删除文件
{
class Program
{
static void Main(string[] args)
{
// C#追加文件
StreamWriter sw = File.AppendText(Server.MapPath(".") + "\\myText.txt"); //这里有问题???
sw.WriteLine("追逐理想");
sw.WriteLine("kzlll");
sw.WriteLine(".NET笔记");
sw.Flush();
sw.Close(); }
}
}麻烦大家给我看看啊,哪里有问题,命名空间还是server.mappath那里有问题,谢谢了
如果你要取得当前程序执行的目录,请使用 AppDomain.CurrentDomain.BaseDirectory属性
using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Web.HttpContext.Current.Server.MapPath; namespace 追加文件删除文件
{
class Program
{
static void Main(string[] args)
{
// C#追加文件
StreamWriter sw = File.AppendText(Application.StartupPath+ "\\myText.txt"); //这里有问题???
sw.WriteLine("追逐理想");
sw.WriteLine("kzlll");
sw.WriteLine(".NET笔记");
sw.Flush();
sw.Close(); }
}
}