檔案存取原理與應(yīng)用.ppt_第1頁(yè)
檔案存取原理與應(yīng)用.ppt_第2頁(yè)
檔案存取原理與應(yīng)用.ppt_第3頁(yè)
檔案存取原理與應(yīng)用.ppt_第4頁(yè)
檔案存取原理與應(yīng)用.ppt_第5頁(yè)
已閱讀5頁(yè),還剩39頁(yè)未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、第六章,1,檔案存取原理與應(yīng)用,I/O Processing,實(shí)驗(yàn)?zāi)康?學(xué)習(xí)經(jīng)由C#基本的IO class能夠?qū)n案/資料夾進(jìn)行操作 在PDA上實(shí)作檔案總管功能 顯示檔案/資料夾路徑 顯示檔案/資料夾建立、讀取、寫(xiě)入時(shí)間,實(shí)驗(yàn)內(nèi)容,System.IO namespace,System.IO,FileStream 讀取、寫(xiě)入、開(kāi)啟和關(guān)閉檔案系統(tǒng)上的檔案 MemoryStream 對(duì)記憶體做讀取、寫(xiě)入動(dòng)作 StreamReader和StreamWriter 將字元以特定編碼,從 Streams 讀取字元或?qū)懭隨treams BinaryReader和BinaryWriter 可對(duì) Streams

2、當(dāng)作二進(jìn)位值讀取和寫(xiě)入編碼字串,System.IO,Directory和DirectoryInfo 複製、移動(dòng)、重新命名、建立和刪除目錄 File和FileInfo 複製、移動(dòng)、重新命名、建立和刪除檔案 Path 提供與檔案或目錄路徑相關(guān)的操作 所有Directory和File方法都是static的,不需要事先創(chuàng)造一個(gè)物件,System.IO,Streams 將Bytes讀取或?qū)懭霗n案中 (例如執(zhí)行l(wèi)ow-level file I/O) Byte-level I/O是利用Stream物件來(lái)完成的,Stream (base),FileStream,MemoryStream,System.IO,R

3、eaders and writers 在higher level讀取和寫(xiě)入,例如傳輸value data types, Unicode characters, strings, and lines of text,TextReader (base),StreamReader,StringReader,TextWriter (base),StreamWriter,StringWriter,BinaryReader,BinaryWriter,System.IO,File system 用來(lái)操作檔案,像是建立、刪除、找尋、複製,還有維護(hù)屬性,FileSystemInfo (base),Directo

4、ryInfo,FileInfo,Directory,File,Path,Three General Categories,Streams(byte-level I/O) Readers and writers File system,Streams(byte-level I/O),Stream物件傳輸bytes資料於儲(chǔ)存裝置的媒介,像是file或是網(wǎng)路socket 因?yàn)閎yte是檔案?jìng)鬏斪罨镜膯挝?,Stream物件提供基本檔案?jìng)鬏數(shù)哪芰?,不限制於特定的?chǔ)存媒介,Streams(byte-level I/O),FileStreams contructor,FileStream fs = new

5、 FileStream(string path, FileMode mode); FileStream fs = new FileStream(string path, FileMode mode, FileAccess access); FileStream fs = new FileStream(string path, FileMode mode, FileAccess access, FileShare share);,Streams(byte-level I/O),FileAccess型態(tài)用來(lái)描述檔案的存取權(quán)限, FileMode用來(lái)設(shè)定開(kāi)檔的方式,而 FileShare型態(tài)用來(lái)描述

6、檔案開(kāi)啟的屬性 FileMode,Streams(byte-level I/O),FileAccess FileShare,Streams(byte-level I/O),FileStream,Encoding class,當(dāng)資料在傳輸時(shí),它可被encode或是decode。Encoding將資料從Unicode轉(zhuǎn)換成其他character set。在所有支援能轉(zhuǎn)換的character set中,都是被應(yīng)用為用bytes的形式在儲(chǔ)存媒介與stream中傳輸 選擇所想要的Encoding方式,並且指定於reader或是writer的constructor的參數(shù)中。當(dāng)reader或writer物件

7、被建立之後,Encoding的特性將無(wú)法被改變,Encoding class,Streams(byte-level I/O),開(kāi)啟檔案,若是檔案不存在則建立新的檔案,並且寫(xiě)入新的文字資料,FileStream fs = new FileStream(.Variables.txt, FileMode.Append, FileAccess.Write, FileShare.Write); String Line = This is a new line.; byte info = Encoding.ASCII.GetBytes(Line); fs.Write(info, 0, info.Lengt

8、h); fs.Close();,Streams(byte-level I/O),開(kāi)啟檔案並讀取所有文字資料,FileStream f = new FileStream(.Variables.txt, FileMode.Open); byte buffer = new byte10000; int count = f.Read(buffer, 0, (int)f.Length); string text = Encoding.ASCII.GetString(buffer, 0, count); f.Close();,Streams(byte-level I/O),Stream-derived c

9、lasses提供一個(gè)一般的介面來(lái)對(duì)不同的儲(chǔ)存媒介作byte-oriented存取 如果我們面對(duì)的是bytes那當(dāng)然沒(méi)有問(wèn)題,但如果我們需要讀取和寫(xiě)入two bytes per character的Unicode時(shí)該如何? 或許你還可能讀取或?qū)懭雐ntegers, floating-point values, or strings in their native mode 因此你可能想要有更highe level的抽象概念,像是讀取或?qū)懭攵嘈形淖仲Y料,Three General Categories,Streams(byte-level I/O) Readers and writers File

10、 system,Readers and writers,在higher level讀取和寫(xiě)入,例如傳輸value data types, Unicode characters, strings, and lines of text,Readers and writers,StreamReaders constructor,StreamReader fs = new StreamReader(Stream); StreamReader fs = new StreamReader(String); StreamReader fs = new StreamReader(Stream, Encodin

11、g); StreamReader fs = new StreamReader(String, Encoding);,Readers and writers,第一種constructor要傳入Stream的參數(shù),因此先利用FileStream開(kāi)啟一檔案,再當(dāng)作參數(shù)傳入 第二種constructor較簡(jiǎn)單,直接傳入檔案名稱(chēng)及路徑即可,FileStream f = new FileStream(.Variables.txt, FileMode.Open); StreamReader sr = new StreamReader(f),StreamReader sr = new StreamReader

12、(.Variables.txt),Readers and writers,StreamReader,Readers and writers,會(huì)出現(xiàn)一個(gè)messagebox視窗顯示Variables.txt檔案中的所有文字資料,StreamReader sr = new StreamReader(.Variables.txt); MessageBox.Show(sr.ReadToEnd(); sr.Close();,Readers and writers,StreamWriters constructor,StreamWriter fs = new StreamWriter(Stream); S

13、treamWriter fs = new StreamWriter(String); StreamWriter fs = new StreamWriter(Stream, Encoding); StreamWriter fs = new StreamWriter(String, Encoding);,Readers and writers,StreamWriter,Readers and writers,將三行文字資料寫(xiě)入Variables.txt檔案中,StreamWriter sw = new StreamWriter(.Variables.txt); sw.WriteLine(This

14、is); sw.WriteLine(a text) sw.WriteLine(file); sw.Close();,實(shí)作演練,用StreamReader和StreamWriter的方式重新實(shí)作一次同樣的例子,Three General Categories,Streams(byte-level I/O) Readers and writers File system,實(shí)驗(yàn)?zāi)康?在PDA上實(shí)作檔案總管功能 顯示檔案/資料夾路徑 顯示檔案/資料夾建立、讀取、寫(xiě)入時(shí)間,File system,用來(lái)操作檔案,像是建立、刪除、找尋、複製,還有維護(hù)屬性 Directory和File classes擁有st

15、atic methods。不用建立實(shí)體物件,就可以經(jīng)由class reference呼叫static methods,File system,File,File system,Directory,File system,Directory (cont.),實(shí)作演練,在檔案總管例子下,新增讀取窗格,點(diǎn)選讀取按鈕後,可讀取文字檔(txt)並顯示文字檔內(nèi)容於讀取窗格內(nèi)。 在檔案總管例子下,新增功能列功能-檔案複製、檔案移動(dòng)、檔案刪除,以加強(qiáng)檔案總管功能。,實(shí)驗(yàn)?zāi)康?學(xué)習(xí)利用PDA提供使用者設(shè)定的功能鍵,覆寫(xiě)自己想要實(shí)作的功能,實(shí)驗(yàn)內(nèi)容,設(shè)定PDA功能鍵指定PDA本身提供的程式 將PDA功能鍵和自行撰

16、寫(xiě)的應(yīng)用程式做對(duì)應(yīng) Hardware Button class,PDA設(shè)定功能鍵,一般各家PDA廠商生產(chǎn)PDA皆會(huì)設(shè)置數(shù)個(gè)不等的功能鍵以對(duì)應(yīng)PDA內(nèi)建或廠商內(nèi)附之程式,此功能鍵功能在設(shè)定選單中可自行設(shè)定 Windows Mobile 6 SDK emulator提供設(shè)定Button 2功能鍵,因此實(shí)驗(yàn)之覆寫(xiě)按鍵為Button 2,PDA設(shè)定功能鍵,Hardware Button,在Pocket PC 上設(shè)定硬體按鈕功能步驟 建立 HardwareButton 物件 將 AssociatedControl 屬性設(shè)定為要啟動(dòng)的表單或控制項(xiàng) 將 HardwareKey 屬性設(shè)為 HardwareKeys之列舉值 硬體按鈕與控制項(xiàng)產(chǎn)生關(guān)聯(lián)時(shí) 按下按鈕,控制項(xiàng)會(huì)接收到 KeyD

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論