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
|
No responses found. Be the first to respond and make money from revenue sharing program.
|