infile = open("D:/test.txt", "r") #打开文件 outfile = open("D:/pp2.txt", "w") # 内容输出 for line in infile: #按行读文件,可避免文件过大,内存消耗 outfile.write(line.replace(' ', ' '))#first is old ,second is new infile.close() #文件关闭 outfile
Shell脚本,执行解释速度快.代码简单易于理解.在shell代码编写过程中,经常会用到读取文件内容. 写法一: ---------------------------------------------------------------------------- #!/bin/bash while read line do echo $line done < file(待读取的文件) ------------------------------------------
/* var browser=navigator.appName var b_version=navigator.appVersion var version=b_version.split(";"); var trim_Version=version[1].replace(/[ ]/g,""); if(browser=="Microsoft Internet Explorer" && trim_Version=="MS
用c#读取文件内容中文是乱码的解决方法: //方法1: StreamReader din = new StreamReader(@"C:\1.txt", System.Text.Encoding.GetEncoding("gb2312")); string html = ""; while (din.Peek() > -1) { html = html + din.ReadToEnd(); } din.Close(); //方法2: Str