为什么输出字符串中带大括号“{}”时:
Console输出没有问题,而StreamWriter输出就报错呢,什么原因?
目的:遍历文件夹名,然后写入txt文本中。
然而有的文件夹名中包含了大括号{},文件夹命名是允许的,但是StreamWriter写入却遇到了问题,请指教。
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string folderTPath = @"C:\temp\456.txt"; //写入文件地址
StreamWriter sw = new StreamWriter(folderTPath, false, Encoding.UTF8); //创建写入文件对象
string name="11111{1}"; //输出字符串
Console.WriteLine(name); //Console输出字符串没有问题
sw.WriteLine(name, true); //StreamWriter输出字符串报错呢?
sw.Close();
///////////////////////////////////////////////////////
Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);
}
}
}




 
	
                                                 VIP会员
VIP会员 购物车
购物车


 私信
                         私信 
                     
					 
					 发表新帖
发表新帖 立即签到
立即签到 
        		  
        		 
         		 关注
关注
                  回复
 回复 支持(
                	支持( 反对(
                    反对(
 
               			  
                







 
                     
                     
					 
						 
						 
						 
						