C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » File Operations »

Decode your file using UTF8


Posted Date: 22 Oct 2009    Resource Type: Code Snippets    Category: File Operations
Author: Shunmuganathan MMember Level: Diamond    
Rating: 1 out of 5Points: 10




We can decode our file using UTF8.
Following is the sample code for decode the txt file

Namespace part

using System;
using System.IO;
using System.Text;



Code part

class Class1{
static void Main(string[] args) {
byte[] MybyteData = new byte[100];
char[] MycharData = new Char[100];

FileStream MyFileStream = new FileStream("MyText.txt",FileMode.Open);
MyFileStream.Seek(55,SeekOrigin.Begin);
MyFileStream.Read(MybyteData,0,100);


Decoder MyDecoder = Encoding.UTF8.GetDecoder();
MyDecoder.GetChars(byData, 0, MybyteData.Length, MycharData, 0);
Console.WriteLine(MycharData);
}
}


Code Explanation

1. Create the Byte array
2. Create Char array
3. open the file using the file stream
4. read the file and get it in the byte array
5. Create the instance of the Decoder using Encoding.UTF8.GetDecoder()
6. fill the data into the char arry and write it.

Thanks
Nathan



Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Decode your file using UTF8  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Create and Write into Log file
Previous Resource: Images From the Database
Return to Discussion Resource Index
Post New Resource
Category: File Operations


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use