/*Introducing the System.IO namespace in the code header*/ //The first of these methods using(FileStream fs=NewFileStream (@"C:\a.txt", FileMode.Open) { using(StreamReader sr=NewStreamReader (FS) {if(Sr.) ReadToEnd = =string. Empty) {//is empty } } } //The second method ofFileInfo fi=NewFileInfo (@"C:\a.txt"); if(FI. length==0){ //is emptyIn contrast, the second method is simpler2This method is suitable for plain text files, such as TXT, ini,html,xml, etc., because they do not include any formatting information. It is not suitable for files such as Doc,xls,zip, RAR, etc., because even if these files are new empty files, they will include some application information or format information. The best way to differentiate is that you open an application (such as Word, Excel), create a new empty file, and see if its size is0。
if (file.exists (@ "file path")) {//Presence}else{//not present}
Determine if the file is empty or exists