WriteAllLines 메서드를 사용하여 파일에 배열을 씁니다.
먼저 문자열 배열을 설정하십시오 -
string[] stringArray = new string[] {
"one",
"two",
"three"
}; 이제 WriteAllLines 메소드를 사용하여 위의 배열을 파일에 추가하십시오 -
File.WriteAllLines("new.txt", stringArray); 다음은 전체 코드입니다 -
예시
using System.IO;
using System;
public class Program {
public static void Main() {
string[] stringArray = new string[] {
"one",
"two",
"three"
};
File.WriteAllLines("new.txt", stringArray);
using (StreamReader sr = new StreamReader("new.txt")) {
string res = sr.ReadToEnd();
Console.WriteLine(res);
}
}
} 출력
one two three