io操作主要分為三類:檔案操作、路徑操作、資料夾操作
示例一:
class program
", file.exists(@"c:\demo.txt"));
//用於校驗檔案夾目錄是否存在
directory.exists(@"c:\");
string path = ".";
if (args.length > 0)
else
not found");
}directoryinfo dir = new directoryinfo(path); //獲取當前目錄物件
foreach (fileinfo info in dir.getfiles(".txt")) //遍歷獲取所有檔案字尾名微.txt的檔案
} }
示例一:判斷乙個檔案是否存在,如果不存在則建立,並向檔案內部寫入內容。
class program
filestream fs = new filestream(filename,filemode.create);
binarywriter w = new binarywriter(fs);
for (int i = 0; i < 10; i++)
w.close();
fs.close();
}}
示例三:當檔案已經存在時候向檔案內部新增內容
class program
}public static void writeinfo(string writeinfo,textwriter tw)
",writeinfo);
tw.flush();
}}
示例四:檔案讀取
寫法1:
class program
//檔案流
filestream fs = new filestream(filepath,filemode.open,fileaccess.read);
binaryreader br = new binaryreader(fs);
for (int i = 0; i < 10; i++)
br.close();
fs.close();
console.readline();
}}
寫法2:
class program
using (streamreader sr = file.opentext(filepath))
console.writeline("the end of the stream!");
sr.close();
}console.readline();
}}
C 中常用的操作
1 enable usb phy and use remote wake up define drvusb enable usb outp32 usbd attr 0x7d0 define outp32 port,value volatile unsigned int port value 這個巨集...
C 中常用的經典檔案操作方
c 追加檔案 sw.writeline 追逐理想 sw.writeline kzlll sw.writeline net筆記 sw.flush sw.close c 拷貝檔案 c 刪除檔案 file.delete delfile c 移動檔案 c 建立目錄 遞迴刪除資料夾及檔案 實現乙個靜態方法將指...
C 常用IO操作
建立資料夾 如果資料夾路徑不存在則建立資料夾 if directory.exists path directory.createdirectory path 遞迴建立資料夾 public void createdir string fullpath view code 刪除整個資料夾 directo...