내가 만들고 싶다 .txt 파일 및 쓰기 정보기술 (it), 파일의 경우, 이미 몇 개 더 하고 싶어서 덮어쓰기/추가 흐름선:
string path = @"E:\AppServ\Example.txt";
if (!File.Exists(path))
{
File.Create(path);
TextWriter tw = new StreamWriter(path);
tw.WriteLine("The very first line!");
tw.Close();
}
else if (File.Exists(path))
{
TextWriter tw = new StreamWriter(path);
tw.WriteLine("The next line!");
tw.Close();
}
그러나 첫 번째 줄은 항상 프레젠테이션이든 덮어씁니다 것으로 보인다. 피할 수 있는 방법은 먹어서나 같은 줄에 (I& # 39 m, 이를 통해 받을시간은 루프)?
List. [올바른 구성자를] (http://msdn.microsoft.com/en-us/library/36b035cb.aspx):
else if (File.Exists(path))
{
using(var tw = new StreamWriter(path, true))
{
tw.WriteLine("The next line!");
}
}
string path = @"E:\AppServ\Example.txt";
File.AppendAllLines(path, new [] { "The very first line!" });
또한 지켜보리니 file.a펜들테스트 (). 줄 바꿈 추가하기에서는 아펜들린스 불지옥으 않고도 각 줄 것을 좁히어 구하겠죠
두 방법 모두 파일을 만들 수 있도록 # 39, t, t # 39 doesn& 경우 don& 존재할 수 있다.
string path=@"E:\AppServ\Example.txt";
if(!File.Exists(path))
{
File.Create(path).Dispose();
using( TextWriter tw = new StreamWriter(path))
{
tw.WriteLine("The very first line!");
}
}
else if (File.Exists(path))
{
using(TextWriter tw = new StreamWriter(path))
{
tw.WriteLine("The next line!");
}
}
Filestream 사용할 수 있습니다. 이 경우 모든 처리가 가능합니다.
Microsoft 에서 문서 파일 안에 추가 단일 통화 존재하지 않는 경우 만들 수 있습니다. File.a펜들테스트 방법 (문자열 (String)
다른 버전이 .net Framework (현재 버전)
파일 (file 지정한 문자열을 첨부됩니다 열었든, 파일 및 종료됩니다. 파일이 없는 경우, 이 방법을 사용하면 지정한 문자열을 쓰기뿐만 파일을 파일 (file), 종료됩니다. 이름공간이: 시스템실리오 조립품을: 마스코리브 (in 마스코리발들러)
문법 C # C++F # VB public void 아펜들테스트 (정적임 구체화하십시오 경로, 구체화하십시오 내용 ) 매개변수입니다 경로 유형: 시스템.슬링 파일 첨부하려면 지정한 문자열을. 내용 유형: 시스템.슬링 문자열 첨부하려면 파일.
[아펜들테스트] [1]
[1]: 이아스파스 cs 저장으로의 랭 =, = 사샤프 https://msdn.microsoft.com/en-us/library/microsoft.synchronization.syncdirectionorder (v = sql.105) # 코드 스니핏 1 cs 랭 1&?
이거 드세요.
string path = @"E:\AppServ\Example.txt";
if (!File.Exists(path))
{
using (var txtFile = File.AppendText(path))
{
txtFile.WriteLine("The very first line!");
}
}
else if (File.Exists(path))
{
using (var txtFile = File.AppendText(path))
{
txtFile.WriteLine("The next line!");
}
}