下面资料是关于C#通过文件流读取文件内容的内容,希望对小伙伴们有较大用途。
public static string getFileAsString(string fileName) { StreamReader sReader = null; string contents = null; try { FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); sReader = new StreamReader(fileStream); contents = sReader.ReadToEnd(); } finally { if(sReader != null) { sReader.Close(); } } return contents; }