최근 진행 상황을 추적하고 싶습니다. HTTPWebRequest
업로드 진행률. 그래서 저는 작게 시작하여 간단한 텍스트 파일을 버퍼링하여 읽기 시작했습니다. 그때C에서 파일 읽기 (/ 쓰기)
File.ReadAllText("text.txt");
같은 간단한 작업 등 모든 스트림, 독자, 작가로, 아래 같은 지거나 일도 제거 할 수 있다는 것을 발견? 또한 아래 코드는 작동하지 않습니다. 어쩌면 내가 뭔가 잘못 했어, 내가 읽을 수있는 방법 (내가 쓰는 것 같아. 비슷한 것 같다) 버퍼에 그래서 내가 진행 상황을 추적 할 수있는, 스트림이 로컬하지 가정합니다.
byte[] buffer = new byte[2560]; // 20KB Buffer, btw, how should I decide the buffer size?
int bytesRead = 0, read = 0;
FileStream inStream = new FileStream("./text.txt", FileMode.Open, FileAccess.Read);
MemoryStream outStream = new MemoryStream();
BinaryWriter outWriter = new BinaryWriter(outStream);
// I am getting "Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection."
// inStream.Length = Length = 9335092
// bytesRead = 2560
// buffer.Length = 2560
while ((read = inStream.Read(buffer, bytesRead, buffer.Length)) > 0)
{
outWriter.Write(buffer);
//outStream.Write(buffer, bytesRead, buffer.Length);
bytesRead += read;
Debug.WriteLine("Progress: " + bytesRead/inStream.Length * 100 + "%");
}
outWriter.Flush();
txtLog.Text = outStream.ToString();
WebRequest 클래스 업데이트 : 텍스트를 (내가 틀릴 수도 있지만) 읽는 것 같다 때문에 솔루션
byte[] buffer = new byte[2560];
int bytesRead = 0, read = 0;
FileStream inStream = File.OpenRead("text.txt");
MemoryStream outStream = new MemoryStream();
while ((read = inStream.Read(buffer, 0, buffer.Length)) > 0)
{
outStream.Write(buffer, 0, buffer.Length);
bytesRead += read;
Debug.WriteLine((double)bytesRead/inStream.Length * 100);
}
inStream.Close();
outStream.Close();
"아래 코드도 작동하지 않습니다." - 자신을 돕고 예상대로 작동하지 않는 것을 설명하는 방법에 대해 ...? –
@Mitch 밀, 아 오류를 추가하는 것을 잊어 버렸습니다. 게시물을 업데이트했습니다. 'while' 줄에 오류가 발생했습니다. –