午夜国产狂喷潮在线观看|国产AⅤ精品一区二区久久|中文字幕AV中文字幕|国产看片高清在线

    asp.net(c#)文件操作函數(shù)大全
    來源:易賢網(wǎng) 閱讀:605 次 日期:2014-10-21 09:53:37
    溫馨提示:易賢網(wǎng)小編為您整理了“asp.net(c#)文件操作函數(shù)大全”,方便廣大網(wǎng)友查閱!

    對于文件流的操作,首先你得引用命名空間:using system.io;對文件的操作主要指兩方面:第一,是對文件本身進(jìn)行操作;第二,是對文件內(nèi)容進(jìn)行操作。

    如果是前者,樓主可以使用system.io.fileinfo等類型,對文件進(jìn)行操作;后者的話可以通過system.io.streamreader,streamwriter,filestreamd等流對象對文件內(nèi)容進(jìn)行操作。

    asp.net(c#)對文件操作的方法(讀取,刪除,批量拷貝,刪除...)

    using system.data;

    using system.configuration;

    using system.web;

    using system.web.security;

    using system.web.ui;

    using system.web.ui.webcontrols;

    using system.web.ui.webcontrols.webparts;

    using system.web.ui.htmlcontrols;

    using system.text;

    using system.io;

    namespace ec

    {

    ///

    /// fileobj 的摘要說明

    ///

    public class fileobj

    {

    構(gòu)造函數(shù)

    idisposable 成員

    取得文件后綴名

    #region 寫文件

    /****************************************

    * 函數(shù)名稱:writefile

    * 功能說明:當(dāng)文件不存時(shí),則創(chuàng)建文件,并追加文件

    * 參 數(shù):path:文件路徑,strings:文本內(nèi)容

    * 調(diào)用示列:

    * string path = server.mappath(default2.aspx);

    * string strings = 這是我寫的內(nèi)容啊;

    * ec.fileobj.writefile(path,strings);

    *****************************************/

    ///

    /// 寫文件

    ///

    /// 文件路徑

    /// 文件內(nèi)容

    public static void writefile(string path, string strings)

    {

    if (!system.io.file.exists(path))

    {

    //directory.createdirectory(path);

    system.io.filestream f = system.io.file.create(path);

    f.close();

    f.dispose();

    }

    system.io.streamwriter f2 = new system.io.streamwriter(path, true, system.text.encoding.utf8);

    f2.writeline(strings);

    f2.close();

    f2.dispose();

    }

    #endregion

    #region 讀文件

    /****************************************

    * 函數(shù)名稱:readfile

    * 功能說明:讀取文本內(nèi)容

    * 參 數(shù):path:文件路徑

    * 調(diào)用示列:

    * string path = server.mappath(default2.aspx);

    * string s = ec.fileobj.readfile(path);

    *****************************************/

    ///

    /// 讀文件

    ///

    /// 文件路徑

    ///

    public static string readfile(string path)

    {

    string s = ;

    if (!system.io.file.exists(path))

    s = 不存在相應(yīng)的目錄;

    else

    {

    streamreader f2 = new streamreader(path, system.text.encoding.getencoding(gb2312));

    s = f2.readtoend();

    f2.close();

    f2.dispose();

    }

    return s;

    }

    #endregion

    #region 追加文件

    /****************************************

    * 函數(shù)名稱:fileadd

    * 功能說明:追加文件內(nèi)容

    * 參 數(shù):path:文件路徑,strings:內(nèi)容

    * 調(diào)用示列:

    * string path = server.mappath(default2.aspx);

    * string strings = 新追加內(nèi)容;

    * ec.fileobj.fileadd(path, strings);

    *****************************************/

    ///

    /// 追加文件

    ///

    /// 文件路徑

    /// 內(nèi)容

    public static void fileadd(string path, string strings)

    {

    streamwriter sw = file.appendtext(path);

    sw.write(strings);

    sw.flush();

    sw.close();

    sw.dispose();

    }

    #endregion

    #region 拷貝文件

    /****************************************

    * 函數(shù)名稱:filecoppy

    * 功能說明:拷貝文件

    * 參 數(shù):orignfile:原始文件,newfile:新文件路徑

    * 調(diào)用示列:

    * string orignfile = server.mappath(default2.aspx);

    * string newfile = server.mappath(default3.aspx);

    * ec.fileobj.filecoppy(orignfile, newfile);

    *****************************************/

    ///

    /// 拷貝文件

    ///

    /// 原始文件

    /// 新文件路徑

    public static void filecoppy(string orignfile, string newfile)

    {

    file.copy(orignfile, newfile, true);

    }

    #endregion

    #region 刪除文件

    /****************************************

    * 函數(shù)名稱:filedel

    * 功能說明:刪除文件

    * 參 數(shù):path:文件路徑

    * 調(diào)用示列:

    * string path = server.mappath(default3.aspx);

    更多信息請查看IT技術(shù)專欄

    更多信息請查看網(wǎng)絡(luò)編程
    易賢網(wǎng)手機(jī)網(wǎng)站地址:asp.net(c#)文件操作函數(shù)大全
    由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!

    2025國考·省考課程試聽報(bào)名

    • 報(bào)班類型
    • 姓名
    • 手機(jī)號(hào)
    • 驗(yàn)證碼
    關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺(tái) | 手機(jī)站點(diǎn) | 投訴建議
    工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
    云南網(wǎng)警備案專用圖標(biāo)
    聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號(hào):hfpxwx
    咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)
    云南網(wǎng)警報(bào)警專用圖標(biāo)