首页 > 代码库 > c#中对txt文件的读取与写入,针对二维数组
c#中对txt文件的读取与写入,针对二维数组
class Program { public static int ROW = 5; public static int COL = 6; static string[,] str = new string[ROW, COL]; static void Main(string[] args) { Read(); Write(); } public static void Read() { string[] a; StreamReader sr = new StreamReader("D:\\imx_2016-2017\\study\\001.txt", Encoding.Default); for (int i = 0; i < ROW; i++) { String line = sr.ReadLine(); a = line.Split(‘,‘); for (int j = 0; j < COL; j++) { str[i, j] = a[j]; //Console.Write(str[i, j]); //Console.Write("\t"); } //Console.WriteLine(); } //Console.ReadKey(); } public static void Write() { FileStream fs = new FileStream("D:\\imx_2016-2017\\study\\002.txt", FileMode.Create); StreamWriter sw = new StreamWriter(fs); for (int i = 0; i < ROW; i++) { for (int j = 0; j < COL; j++) { sw.Write(str[i,j]); } sw.WriteLine(); } //清空缓冲区 sw.Flush(); //关闭流 sw.Close(); fs.Close(); } }
c#中对txt文件的读取与写入,针对二维数组
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。