當前位置:成語大全網 - 漢語詞典 - C#將數組中的數據寫入文本

C#將數組中的數據寫入文本

public void WriteToTxt(string[]str,string filePath)

{

for(int I = 0;我& lt海峽。長度;i++)

{

嘗試

{

文件。AppendAllText(filePath,str[I]);

//如果需要換行符,根據具體文件類型添加換行符。

//比如:記事本文件(txt文件寫為):

//文件。AppendAllText(filePath,str[I]+" \ r \ n ");

//數組也可以是其他數組,可以寫成:

//文件。AppendAllText(filePath,str[i].ToString()+" \ r \ n ");

}

捕捉

{

}

}

}