The filestream class operates on Byte and byte arrays, while the stream class operates on character data.Streamwriter allows you to write characters and strings to files. It processes underlying conversions and writes data to filestream objects. Streamreader is similar.Instance:
Code
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--> /// /// Read/write operations on text files /// Private Static Void Textfileoperat
/--> Using System; Using System. IO; Namespace Streamwriterreaderapp{ Public Class Mystreamwriterreader{ Static Void Main ( String [] ARGs){Console. writeline ( " * ***** Fun with streamwriter/streamreader ***** \ n " ); // Get a streamwriter and write string data. // Streamwriter writer = file. createtext ("thoughts.txt "); Streamwriter = New Streamwriter ( " Reminders.txt " );Writer. writeline ( " Don't forget Mother's Day this year " );Writer. writeline (
// Directoryinfo dir = new directoryinfo ("C :\\");// System. Io. filesysteminfo [] fiis = dir. getfilesysteminfos ();// If (FS [1] is directoryinfo)//{//// Fi [1] is a folder//}// If (FS [1] is fileinfo)//{//// FCM [1] is a file//}Private void operatorfilebtn_click (Object sender, eventargs E){Fileinfo Fi = new fileinfo ("aa.txt ");If (Fi. exists){// Append information to the fileUsing (streamwriter Sw = Fi. appendtext ()){Sw. Write ("this is the test information :::");}}Else{// Create a file a
Microsoft SQL Server has an SDK library that provides various commands equivalent to the Manager function. As long as the corresponding Dll is referenced, the corresponding commands can be executed (. SQL.
1. reference the corresponding DLL (version: SQL 2008)
REFERENCE The following DLL, where the file is located: Install Mssql directory + Microsoft SQL Server \ 100 \ SDK \ Assemblies
Microsoft. SqlServer. ConnectionInfo. dllMicrosoft. SqlServer. Dmf. dllMicrosoft. SqlServer. Management. Sdk. S
model for reading and writing objects to bridge this gap. These objects encapsulate stream objects and allow you to write more complex data.
You can find the File class, FileStream class, FileInfo class, StreamWriter class, And StreamReader class in the. net Framework.
FileStream fileStream = new FileStream (@ "c: \ temp \ aa.txt", FileMode. Create );StreamWriter w = new StreamWriter (fileStream );
Same as StreamWriter w = File. CreateText (@ "c: \ temp \ aa.txt ");
W. WriteLine ("what is this
with the webHandle command. The following example:
Most importantly, the. ashx file type has been registered in IIS, so you do not have to execute any IIS configuration when publishing an application.
Whether to use the configuration file or the. ashx file is just a matter of personal preference. However, the. ashx file is usually used for simple extensions designed for a single Web application.
Configuration files give you more flexibility
The SourceHandler class is located in the App_Code di
file
Setfile (); // set file attributes
}
In addition, the file class provides more support for text.
· Appendtext: append text to an existing file.
· Createtext: Creates or opens a new file for writing text.
· Opentext: open an existing text file for reading.
But the above method mainly on the UTF-8 encoding text operations, which is not flexible enough. We recommend that you use the following code to operate the TXT file.
· Read the TXT file. The s
RW objectRW. Close ();// Open a text fileStreamreader sr = file. opentext ("E: \ hitest.txt ");Stringbuilder output = new stringbuilder ();String RL;While (RL = Sr. Readline ())! = NULL){Output. append (RL + "\ r \ n ");}MessageBox. Show (output. tostring ());Sr. Close ();}Private void button8_click (Object sender, eventargs E){Filestream FS = new filestream ("E: \ fstest.txt", filemode. Create );// Create streamwriter to prepare for writingStreamwri
exists.
{
Copyfile (); // copy a file
Deletefile (); // delete an object
Movefile (); // move the file
}
Else
{
Makefile (); // generate a file
Openfile (); // open the file
Setfile (); // set file attributes
}
In addition, the file class provides more support for text.
· Appendtext: append text to an existing file.
· Createtext: Creates or opens a new file for writing text.
· Opentext: open an existing text file for reading.
But the above method mai
(After criticism and guidance from many netizens, this method does not read files from the memory, but reads files one byte by byte, which is much slower than the method used to read Delphi bytes into the memory. This method is only suitable for old machines. If the memory is not enough, the current memory is very cheap. Therefore, this method is out of date. The following is some advice from netizens, the Readline method is used. The speed is about 6 seconds .)
Public
Static Ilist Lon
nvarchar (100 ))Returns intAsBeginDeclare @ A intSet @ A = 0While @ STR BeginSet @ A = (case when Unicode (left (@ STR, 1) between 12592 and 12687Or Unicode (left (@ STR, 1) between 44032 and 55203Then 1Else 0 end)Set @ STR = right (@ STR, Len (@ Str)-1)EndReturn @End
-- Call:Declare @ A nvarchar (100)Set @ A = n'abc's country 123'Select DBO. HW (@)
-- Return: 1
Set @ A = n' ABC China 123'Select DBO. HW (@)
-- Return: 0
4. Why are the Chinese characters read from the file garbled?
. currentdomain. basedirectory, file );If(File. exists (cnblogs )){Using(Streamreader reader = file. opentext (cnblogs) {rtfcnblogs. Text = reader. readtoend ();}}
Added the complete file name path, which is the correct method for reading and writing files. For ASP. NET applications, you can use server. mappath instead,
Or httpcontext. Current. Request. physicalapplicationpath.
Cross-thread access control
Delegate VoidDsettext (string text );
: famous search engines such as Lycos, Hotbot, and Yahoo are used in English. Enter detailed keywords (it must be characteristic to prevent searching for too many items ), adding a PDF at the end may have better results. If it is inconvenient, go to www.5566.org and click search. More than a dozen engines are collected, which is enough for you to check. However, Baidu and Google are generally better! Lycos is also good. Key words are very important. You need to master some skills. Otherwise, it'
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.