File read/write breakpoint Problems

Source: Internet
Author: User

Filestream FS; // create a stream object for reading and writing files, read and write bytes in the file (filestream class reads, writes, opens, and closes files on the file system)
Stream stream;
// Stream object of data with Operation characters.

Byte [] BYT = new byte [512]; // create a byte array;
If (system. Io. file. exists (serverpath) // determine whether the specified file exists.
{
Stream = system. Io. file. openwrite (serverpath); // file. openread read-only mode to open the file for writing. This method is efficient and fast

Stream. Seek (stream. length, seekorigin. Current); // set the position of the current stream (current indicates the reference point of the new position, and length indicates the byte offset of the reference point)
FS = system. Io. file. openread (locpath); // file to be opened for reading
FS. Seek (FS. length, seekorigin. Current); // (seekorigin provides a reference point in the stream) set the current position of the stream to a specified value,
// Current specifies the current position as the reference point, and starts searching for the new position of the returned stream from the point of the reference point.
Int nreadsize = stream. Read (BYT, 0,512); // read the byte block from the stream and write the data into the given buffer.
// The offset parameter specifies the offset (Buffer Index) of the byte in the array. The Count parameter indicates the maximum number of bytes read from this stream. The returned value is the actual number of bytes to read, or if it reaches the end of the stream, the value is zero. If the read operation succeeds, the number of bytes read before the current position of the stream. If an exception occurs, the current position of the stream remains unchanged.

// The read method returns zero only after it reaches the end of the stream. Otherwise, read always reads at least one byte from the stream before returning. If no data is available in the stream after read is called, this method will be blocked until at least one byte of data can be returned. Even if the stream has not reached the end, the implementation can still return less than the requested byte at will

While (nreadsize> 0) // determines whether it reaches the end of the stream.
{
FS. Write (BYT, 0,512);/ffer byte array. This method copies count bytes from the buffer to the current stream.
// Offset, the byte offset starting from scratch in the buffer, from which the byte is copied to the current stream.
// Count the number of bytes to write to the current stream.

Nreadsize = stream. Read (BYT, 0,512); // continue reading until the stream byte is 0
}
Stream. Close ();
FS. Close ();

}

Else
{
FS = system. Io. file. Create (serverpath );
Stream = system. Io. file. openread (locpath );
Stream. Seek (0, seekorigin. Begin );
Int readsize = stream. Read (BYT, 0,512 );
While (readsize> 0)
{
FS. Write (BYT, 0,512 );
Readsize = stream. Read (BYT, 0,512 );
}
Stream. Close ();
FS. Close ();
}

}
Protected void button#click (Object sender, eventargs E)
{
Try
{
If (fileupload1.postedfile. filename = "")
{
Response. Write ("select a file ");
Return;
}
Else
{

String filepath = fileupload1.postedfile. filename;
String filename = filepath. substring (filepath. lastindexof ("//") + 1 );

String Path = server. mappath ("file/") + filename;
// String locpath = @ "F:/Game ";
Fileupload (filepath, PATH );

// Fileupload1.postedfile. saveas (PATH );


}
}
Catch (Exception error)
{
Response. Write (error. tostring ());
}

I tested it locally. It can be uploaded but cannot support breakpoints. At the same time, the file size is 0 bytes. Please help me!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.