首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

请问怎么生成以下txt格式的文件

2013-10-16 
请教如何生成以下txt格式的文件啊请教如何生成以下格式的txt文件啊,其中T1398是设备号,通过list集合里动态

请教如何生成以下txt格式的文件啊
请教如何生成以下格式的txt文件啊,其中T1398是设备号,通过list集合里动态取出的,是可变的,294544 1214211是固定的,20131015020000是世界时,我是个新手,请各位高手帮下忙,再次感谢!!

T1398 294544 1214211 ///// ///// 4
20131015020000 /// /// /// /// /// /// //// /// /// /// /// //// 0000 //// //// //// //// //// /// /// //// /// //// ///// ///// //// ///// //// //// //// //// //// //// //// //// //// //// //// //// //// //// //// //// //// //// //// //// ///// ///// ///// ////
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000=
NNNN




[解决办法]

        //
        // 摘要:
        //     创建一个新文件,在其中写入指定的字符串,然后关闭文件。如果目标文件已存在,则覆盖该文件。
        //
        // 参数:
        //   path:
        //     要写入的文件。
        //
        //   contents:
        //     要写入文件的字符串。
        //
        //   encoding:
        //     应用于字符串的编码。
        //
        // 异常:
        //   System.ArgumentException:
        //     path 是一个零长度字符串,仅包含空白或者包含一个或多个由 System.IO.Path.InvalidPathChars 定义的无效字符。
        //
        //   System.ArgumentNullException:
        //     path 为 null 或 contents 为空。
        //
        //   System.IO.PathTooLongException:
        //     指定的路径、文件名或者两者都超出了系统定义的最大长度。例如,在基于 Windows 的平台上,路径必须小于 248 个字符,文件名必须小于 260
        //     个字符。
        //
        //   System.IO.DirectoryNotFoundException:
        //     指定的路径无效(例如,它位于未映射的驱动器上)。
        //
        //   System.IO.IOException:
        //     打开文件时发生了 I/O 错误。
        //
        //   System.UnauthorizedAccessException:
        //     path 指定了一个只读文件。- 或 -在当前平台上不支持此操作。- 或 -path 指定了一个目录。- 或 -调用方没有所要求的权限。
        //
        //   System.IO.FileNotFoundException:
        //     未找到 path 中指定的文件。
        //
        //   System.NotSupportedException:
        //     path 的格式无效。
        //
        //   System.Security.SecurityException:
        //     调用方没有所要求的权限。
        [SecuritySafeCritical]
        public static void WriteAllText(string path, string contents, Encoding encoding);


自己拼好字符串,用这个函数就好了。。
[解决办法]
代码:
using System.IO;
可以参考代码(随手写的 估计有单词错)
void creat(string text,string path)
{
try
{
FileStream fs = new FileStream(path,FileModel.NewCreat);

StreamWriter sw = new StreamWriter (fs);
sw.Write(text);
sw.Full();
sw.Close();
}
catch
{

}
}


请问怎么生成以下txt格式的文件

热点排行