StreamWriter sw = new StreamWriter(filePath, Encoding.Defalut, true); sw.Write(yourData); sw.Close()
楼上的讲的很正确,也可以查阅帮助的file类,他那是调用了streamWriter写了个函数
尽管 解决了,也给另外你一个方法 // fs = new FileStream(strfilename, FileMode.OpenOrCreate, FileAccess.Write); // bw = new BinaryWriter(fs); // Create a file to hold the output. // startIndex = 0; // Reset the starting byte for the new BLOB. // retval = myReader.GetBytes(1, startIndex, outbyte, 0, bufferSize); // Read the bytes into outbyte[] and retain the number of bytes returned. // while (retval == bufferSize) // Continue reading and writing while there are bytes beyond the size of the buffer. // { // bw.Write(outbyte); // bw.Flush(); // // startIndex += bufferSize; // Reposition the start index to the end of the last buffer and fill the buffer. // retval = myReader.GetBytes(1, startIndex, outbyte, 0, bufferSize); // } // if ((int)retval>=1) // bw.Write(outbyte, 0, (int)retval - 1); // Write the remaining buffer. // bw.Flush(); // // bw.Close(); // Close the output file. // fs.Close(); // } // myReader.Close(); // Close the reader and the connection. // db.Close();
sw.Write(yourData);
sw.Close()
// fs = new FileStream(strfilename, FileMode.OpenOrCreate, FileAccess.Write);
// bw = new BinaryWriter(fs); // Create a file to hold the output.
// startIndex = 0; // Reset the starting byte for the new BLOB.
// retval = myReader.GetBytes(1, startIndex, outbyte, 0, bufferSize); // Read the bytes into outbyte[] and retain the number of bytes returned.
// while (retval == bufferSize) // Continue reading and writing while there are bytes beyond the size of the buffer.
// {
// bw.Write(outbyte);
// bw.Flush();
//
// startIndex += bufferSize; // Reposition the start index to the end of the last buffer and fill the buffer.
// retval = myReader.GetBytes(1, startIndex, outbyte, 0, bufferSize);
// }
// if ((int)retval>=1)
// bw.Write(outbyte, 0, (int)retval - 1); // Write the remaining buffer.
// bw.Flush();
//
// bw.Close(); // Close the output file.
// fs.Close();
// }
// myReader.Close(); // Close the reader and the connection.
// db.Close();