1. Trang chủ
  2. » Công Nghệ Thông Tin

Tài liệu C Sharp part 13 pdf

3 366 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề Tài liệu C Sharp part 13 pdf
Tác giả Tuan Anh Nguyen Ngoc
Năm xuất bản 2006
Định dạng
Số trang 3
Dung lượng 72,33 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

mình mởi đầu một cái ví dụ lấy nội dung một file!. public Filestring _pfullpath { ///set fullpath... private string FileContent { ///define string result.. ifthis.FullPath == null ||

Trang 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

{

/// <summary>

/// define string fullpath

/// </summary>

private string _sFullPath;

/// <summary>

/// Contruction of this class

/// </summary>

public File() { }

/// <summary>

/// Contruction of this class

/// </summary>

/// <param name="_pfullpath">The string fullpath.</param> public File(string _pfullpath)

{

///set fullpath

this.FullPath = _pfullpath;

}

/// <summary>

/// Get/Set fullpath string of file

/// </summary>

public string FullPath

{

Trang 2

///return fullpath

get { return this._sFullPath; }

///set fullpath

set { this._sFullPath = value; }

}

/// <summary>

/// Get file content

/// </summary>

/// <returns>return file content as string.</returns>

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;

}

/// <summary>

Trang 3

/// Get file content

/// orverload fileContent method

/// </summary>

/// <param name="_pfullpath">The fullpath string.</param> /// <returns>return file content as string.</returns>

public string FileContent(string _pfullpath)

{

///set fullpath

this.FullPath = _pfullpath;

///call fileContent method, return result

return FileContent();

}

}

}

dauden(UDS)

Ngày đăng: 15/12/2013, 01:16

TỪ KHÓA LIÊN QUAN