逍遥游

一直在想,怎样路好走一点,一直想,一直在崎岖中徘徊。
  首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

文件操作

Posted on 2005-09-27 15:24  逍遥游  阅读(170)  评论(0)    收藏  举报

using System;
using System.IO;


namespace ArLi.CommonPrj {
 internal class FileOp {
  internal static string ReadFileOf(string fileFullName) {
   string fileBody = "";
   try{
    FileStream ObjFile = new FileStream(fileFullName,FileMode.Open,FileAccess.Read,FileShare.ReadWrite);
    StreamReader sw = new StreamReader(ObjFile,System.Text.Encoding.Default);
    fileBody = sw.ReadToEnd();
    sw.Close();
    ObjFile.Close();
   }catch (Exception e){
    fileBody = e.Message.ToString();
   }
   return fileBody;
  }
  internal static string SaveFileOf(string fileFullName,string fileBody) {
   try{
    FileStream ObjFile = new FileStream(fileFullName,FileMode.Create,FileAccess.Write,FileShare.Read);
    StreamWriter sw = new StreamWriter(ObjFile,System.Text.Encoding.Default);
    sw.Write(fileBody);
    sw.Close();
    ObjFile.Close();
    return null;
   }catch (Exception e){
    return e.Message.ToString();
   }
  }
 }
}