1.文件的读取和显示 方法1: f=open(r'G:\2.txt') print f.read() f.close() 方法2: try: t=open(r'G:\2.txt') print t.read() finally: if t: t.close() 方法3: with open(r'g:\2.txt') as g: for line in g: print line python虽然每次打开文件都要关闭,但是可能会由于异常导致未关闭,因此我们最好是手动关闭,方法二通过异常处理来进行,…
TXT文件: txt是微软在操作系统上附带的一种文本格式,文件以.txt为后缀. 从txt文件中读取数据: with open ('xxx.txt') as file: data=file.readlines() 将数据写入txt文件: with open ('xxx.txt','a',encoding='utf-8') as file: file.write('xxxx') 注:a表示append,将数据一行行写入文件 JSON文件: JSON指JavaScript对象表示法(JavaScri…
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace textTest { public partial class WebForm1 : System.Web.UI.Page { p…
class Program { static void Main(string[] args) { EmployeeDAL DAL = new EmployeeDAL(); List<Sys_Employee> list = DAL.GetAll().ToList(); //WriteTxt(list); //DeleDirFile(); Console.WriteLine("请输入文件路径!"); string path = Console.ReadLine(); Rea…