public
partial
class
mainwindow : window
public mainwindow()
initializecomponent();
writetext();
readtext();
///建立檔案
//////匯入檔案
///public
void writetext()
//streamwriter sw = new streamwriter("d:/vs專案檔案/測試2017-9-5/測試2017-9-5/log/log.txt", true);
// 這個建構函式的引數是檔名和乙個boolean值,這個boolean值規定是追加檔案,還是建立新檔案:
// a、false:建立乙個新檔案,或者擷取現有檔案並開啟它。
//b、true:開啟檔案,保留原來的資料。如果找不到檔案,則建立乙個新檔案。
filestream afile = new
filestream(@"d:/vs專案檔案/測試2017-9-5/測試2017-9-5/log/log.txt", filemode.openorcreate);
streamwriter sw = new
streamwriter(afile);
//a 為要寫入的字串組
// string a ="1,2,3,4,5,6,1,1,1,1,1,1,1,1,1,1,1,1";
string a = "barcode";
string b = "wendu";
string c = "yali";
string a = a + b + c;
string strs = ;
foreach (string s in strs)
sw.writeline(s);
sw.close();
///讀取檔案
///public
void readtext()
// streamreader sr = file.opentext("text.txt");
//filestream fs = file.open("text.txt", filemode.open, fileaccess.read);
//streamreader sr = new streamreader(fs, encoding.getencoding("gb2312"));
// string line = sr.readline();
// sr.close();
filestream afile = new
filestream(@"d:/vs專案檔案/測試2017-9-5/測試2017-9-5/log/log.txt", filemode.openorcreate);
streamreader sr =new
streamreader(afile);
//b為要顯示的一行字串;
string b = sr.readline();
string sub = b.substring(0, 13);
//sub為字串b的前13位;
string barcode ="1111111111111";//選取的的**(13位);
if (sub != barcode)
messagebox.show(b);
sr.close();
// fs.close();
python對文字文件的讀寫和刪除操作 1
專案需要,首先需要讀取json格式儲存的文字文件,該文字文件存在指定的目錄中,該目錄下有很多的文字文件,需要在文字文件中找到裡面的calls資料,然後把calls資料返回,供robotframework 呼叫 coding utf 8 import os import glob import dat...
python對文字文件的讀寫和刪除操作 2
專案需要,首先需要讀取json格式儲存的文字文件,該文字文件存在指定的目錄中,該目錄下有很多的文字文件,需要在文字文件中找到裡面的calls資料,然後把calls資料返回,供robotframework 呼叫,然後在另乙個測試用例中將calls資料和時間間隔寫入另乙個文字文件中。coding utf...
C 對文字檔案的幾種讀寫方法總結
計算機在最初只支援ascii編碼,但是後來為了支援其他語言中的字元 比如漢字 以及一些特殊字元 比如 就引入了unicode字符集。基於unicode字符集的編碼方式有很多,比如utf 7 utf 8 unicode以及utf 32。在windows作業系統中,乙個文字檔案的前幾個位元組是用來指定該...