C Sharp part 13

Chia sẻ: Avsdvvsd Qwdqdad | Ngày: | Loại File: PDF | Số trang:3

0
44
lượt xem
15
download

C Sharp part 13

Mô tả tài liệu
  Download Vui lòng tải xuống để xem tài liệu đầy đủ

mình mởi đầu một cái ví dụ lấy nội dung một file! PHP Code: using System; using System.IO; using System.Text; /* * Created by SharpDevelop. * NetDevelop Co., Ltd. * Author: Tuan Anh Nguyen Ngoc * Date: 11/21/2006 *

Chủ đề:
Lưu

Nội dung Text: C Sharp part 13

  1. mình mởi đầu một cái ví dụ lấy nội dung một file! PHP Code: using System; using System.IO; using System.Text; /* * Created by SharpDevelop. * NetDevelop Co., Ltd. * Author: Tuan Anh Nguyen Ngoc * Date: 11/21/2006 * Contact Information. * - Email: [email]info.netdevelop@gmail.com[/email] * - Handheld: +84 905 202 088 */ namespace Ans.Utilities { public class File { /// /// define string fullpath. /// private string _sFullPath; /// /// Contruction of this class. /// public File() { } /// /// Contruction of this class. /// /// The string fullpath. public File(string _pfullpath) { ///set fullpath. this.FullPath = _pfullpath; } /// /// Get/Set fullpath string of file. /// public string FullPath {
  2. ///return fullpath. get { return this._sFullPath; } ///set fullpath. set { this._sFullPath = value; } } /// /// Get file content. /// /// return file content as string. private string FileContent() { ///define string result. string _sResult =""; ///check file path. throw exception if is null or empty. if(this.FullPath == null || this.FullPath.Equals("")) ///throw exception. throw new Exception("Can not get content! The file is not define or declare."); else{ ///check file exists, throw exception if it isn't exist. if (System.IO.File.Exists(this.FullPath)) { ///Create filestream with filemode open and fileaccess read. FileStream _oFileStream = new FileStream(this.FullPath, FileMode.Open, Fi leAccess.Read); ///Create byte array. Byte[] _oByte = new byte[1024]; ///Create UTF8Encoding. UTF8Encoding _oUTF8Encoding = new UTF8Encoding(); ///while filestream read byte > 0. while (_oFileStream.Read(_oByte, 0, _oByte.Length)>0) { _sResult += _oUTF8Encoding.GetString(_oByte); } } else ///throw exception. throw new Exception("Can not get content! The file can not be found."); } ///return result. return _sResult; } ///
  3. /// Get file content. /// orverload fileContent method. /// /// The fullpath string. /// return file content as string. public string FileContent(string _pfullpath) { ///set fullpath. this.FullPath = _pfullpath; ///call fileContent method, return result. return FileContent(); } } } __________________ dauden(UDS)
Đồng bộ tài khoản