Results 1 to 4 of 4

Thread: [2.0] How can I change bytes in a file?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Location
    I'm right here!
    Posts
    849

    Question [2.0] How can I change bytes in a file?

    Hello,
    I am making a small encryption application and for that I want to change
    bytes in my file.
    how can I do this using c#?
    thanks!

    Dekel C.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] How can I change bytes in a file?

    Create a FileStream object, either directly or through the File class, and then use it to read and/or write bytes to the disc file.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: [2.0] How can I change bytes in a file?

    jmcilhinney has a great knowledge but doesn't like to give code samples unless it's very necessary, but I do
    so here is how you can do it, just like he said:
    Code:
    FileStream fs=new FileStream(@"C:\myText.txt",FileMode.Open,FileAccess.ReadWrite);
    while(fs.Position<fs.Length){
    	byte bf=fs.ReadByte();
    	//Do any encryption on the byte
    	fs.WriteByte(bf);
    }
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Location
    I'm right here!
    Posts
    849

    Re: [2.0] How can I change bytes in a file?

    thanks to the both of you!!
    Dekel C.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width