사용자를 SFTP 서버 응용 프로그램에 추가하기 위해 명령 줄 응용 프로그램을 만들 때 사용하는 구성 파일 (.cfg)이 있습니다.C에서 바이트 배열에서 바이트를 제거하고 추가하는 방법
cfg 파일은 cfg 파일의 각 항목에 대해 일정 수의 예약 된 바이트를 가져야합니다. 현재 바이트 배열을 만들고이를 문자열로 변환 한 다음 파일로 복사하여 새 사용자를 파일 끝 부분에 추가하고 있지만 걸림돌을 맞았습니다. 설정 파일은 파일의 끝에 4 바이트를 필요로합니다.
내가 수행해야하는 프로세스는 파일에서 이러한 후행 바이트를 제거하고 새 사용자를 추가 한 다음 끝에 바이트를 추가하는 것입니다.
이제 내 문제의 배경이 보입니다. 바이트 배열에서
어떻게 제거하고 추가 할 바이트 : 여기
질문입니까?여기까지 코드가 있습니다. 한 파일에서 사용자를 읽고 다른 파일에 추가합니다.
static void Main(string[] args)
{
System.Text.ASCIIEncoding code = new System.Text.ASCIIEncoding(); //Encoding in ascii to pick up mad characters
StreamReader reader = new StreamReader("one_user.cfg", code, false, 1072);
string input = "";
input = reader.ReadToEnd();
//convert input string to bytes
byte[] byteArray = Encoding.ASCII.GetBytes(input);
MemoryStream stream = new MemoryStream(byteArray);
//Convert Stream to string
StreamReader byteReader = new StreamReader(stream);
String output = byteReader.ReadToEnd();
int len = System.Text.Encoding.ASCII.GetByteCount(output);
using (StreamWriter writer = new StreamWriter("freeFTPdservice.cfg", true, Encoding.ASCII, 5504))
{
writer.Write(output, true);
writer.Close();
}
Console.WriteLine("Appended: " + len);
Console.ReadLine();
reader.Close();
byteReader.Close();
}
여기에 "다이어그램"이 나와 있습니다.
1) 우선, 사용자
파일 (첨부 된 텍스트) 단부에있는 바이트
(제로)2 추가)
가파일은 (첨부 된 텍스트) (첨부 된 텍스트)에서 바이트 번째 사용자 추가 끝 (제로)
등등.
원하는 크기로 새 배열로 복사합니다. –