C # Save the file as binary

Source: Internet
Author: User

Oledbconnection mycon = new oledbconnection ("provider = Microsoft. jet. oledb.4.0; Data Source = mydb. mdb "); <br/> filestream FS = new filestream (filename, filemode. open, fileaccess. read); <br/> binaryreader BR = new binaryreader (FS); <br/> byte [] mywave = BR. readbytes (INT) FS. length); <br/> Br. close (); <br/> FS. close (); </P> <p> mycon. open (); <br/> string SQL = "insert into mydatabase (WAV, myword) values (@ w AV, '"+ textbox1.text. trim () + "')"; <br/> oledbcommand cmd = new oledbcommand (SQL, mycon); <br/> cmd. parameters. add ("@ WAV", oledbtype. binary, photo. length ). value = mywave; <br/> cmd. executenonquery (); <br/> mycon. close (); </P> <p> # region reads and writes text files <br/> filestream FS = new filestream (@ "R: ''txt.txt", system. io. filemode. openorcreate, <br/> system. io. fileaccess. readwrite, system. io. fileshare. readwrite); <br /> Filestream F = file. open (@ "R: ''f.txt", filemode. openorcreate, <br/> fileaccess. readwrite, fileshare. readwrite); <br/> string S = "Qiu weiguang lov.09823p ''' =! @ # % .; "; <Br/> byte [] INB = system. text. encoding. utf8.getbytes (s); // This is easy to understand as follows <br/> // byte [] INB = new utf8encoding (true ). getbytes (s); // the same effect as above <br/> FS. write (INB, 0, INB. length); <br/> FS. flush (); // clear the buffer <br/> FS. close (); <br/> filestream FF = file. openread (@ "R: ''txt.txt"); <br/> byte [] A = new byte [ff. length]; <br/> ff. read (A, 0, (INT). length); <br/> F. write (A, 0, (INT) ff. length); <br/> ff. close (); <br/> F. close (); <br/> # endregion </P> <p> # region reads and writes binary files <br/> // system. io. binaryreader: Read Binary files <br/> // system. io. binarywriter: Write binary files <br/> // filestream fs1 = new filestream (@ "R: 'gif.gif", filemode. openorcreate, fileaccess. readwrite); <br/> // filestream fs2 = new filestream (@ "R: ''p1.bmp", filemode. openorcreate, fileaccess. readwrite); <br/> // filestream fw = new filestream (@ "R: ''new.txt", filemode. openorcreate, fileaccess. readwrite); <br/> // binaryreader BR = new binaryreader (fs1); <br/> // binarywriter BW = new binarywriter (FW ); <br/> // BW. write (BR. readint32 (); <br/> # endregion

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.