博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C#中对文件的操作小结
阅读量:7065 次
发布时间:2019-06-28

本文共 1043 字,大约阅读时间需要 3 分钟。

1、建立一个文本文件

public class FileClass{    public static void Main()    {    WriteToFile();    }    static void WriteToFile()    {    StreamWriter SW;    SW=File.CreateText("c:\MyTextFile.txt");    SW.WriteLine("God is greatest of them all");    SW.WriteLine("This is second line");    SW.Close();    Console.WriteLine("File Created SucacessFully");    }}

2、读文件

public class FileClass{    public static void Main()    {    ReadFromFile("c:\MyTextFile.txt");    }    static void ReadFromFile(string filename)    {    StreamReader SR;    string S;    SR=File.OpenText(filename);    S=SR.ReadLine();    while(S!=null)    {    Console.WriteLine(S);    S=SR.ReadLine();    }    SR.Close();    }}

3、追加操作

public class FileClass{    public static void Main()    {    AppendToFile();    }    static void AppendToFile()    {    StreamWriter SW;    SW=File.AppendText("C:\MyTextFile.txt");    SW.WriteLine("This Line Is Appended");    SW.Close();    Console.WriteLine("Text Appended Successfully");    }}

 

转载于:https://www.cnblogs.com/leebokeyuan/p/9328280.html

你可能感兴趣的文章
关于LightMapping和NavMesh烘焙的动态载入
查看>>
(转)Android中使用ormlite实现持久化(一)--HelloOrmLite
查看>>
C语言近程型(near)和远程型(far)的区别是什么?
查看>>
jQuery选择器总结
查看>>
《Continuous Delivery》 Notes 1: The problem of delivering software
查看>>
java android 将小数度数转换为度分秒格式
查看>>
一张图知道HTML5布局(图)
查看>>
LINQ To SQL在N层应用程序中的CUD操作、批量删除、批量更新
查看>>
谈谈javascript语法里一些难点问题(一)
查看>>
【BZOJ】1082: [SCOI2005]栅栏(二分+dfs)
查看>>
通过递归组合多维数组!
查看>>
ocp 1Z0-051 23-70题解析
查看>>
关于MFLAGS与MAKEFLAGS
查看>>
NotePad++ for PHP
查看>>
ssh事务回滚,纪念这几个月困扰已久的心酸
查看>>
jQuery中的编程范式
查看>>
比较快速排序,冒泡排序,双向冒泡排序的执行效率
查看>>
还没被玩坏的robobrowser(5)——Beautiful Soup的过滤器
查看>>
Linux 精准获取进程pid--转
查看>>
Servlet、Filter、Listener总结
查看>>