在asp.net中拷贝文件w3wp.exe占用内存的问题。
qugui 2007-01-31 07:34:17 小第开始用的自带的文copyTo,但对大文件操作时,老时报System.OutOfMemoryException 错误,后面查了一下,不能超过系统物理内存的60%,但我现在是1G了,不想加了,就找资料写了一个分块读写的类,这个类在winForm里面没问题,但在web的时候还是一样。请高人指点。
public string copyTo(string infile,string outfile)
{
try
{
iStream = new FileStream( infile , FileMode.Open , FileAccess.Read ) ;
dataToRead = iStream.Length;
FileStream fsWriter = new FileStream(outfile , FileMode.Append , FileAccess.Write );
while (dataToRead > 0)
{
// Verify that the client is connected.
// Read the data in buffer.
length = iStream.Read(buffer, 0, 100000);
// Write the data to the current output stream.
fsWriter.Write( buffer , 0 , buffer.Length );
buffer.Initialize();//= new Byte[100000];
dataToRead = dataToRead - length;
}
fsWriter.Close();
return "true";
}
catch(Exception e)
{
return e.ToString();
}
}