Question Read binary file

Mykhalik

New member
Joined
Dec 12, 2012
Messages
1
Programming Experience
1-3
I'm a beginner in c#.I have to read some data from binary file and convert it to text.I have written such code:
using (System.IO.Stream fileStream = new FileStream(@"D:/batch_job.rst", FileMode.Open, FileAccess.Read))
            {
                using (System.IO.BinaryReader reader = new BinaryReader(fileStream))
                {
                    reader.BaseStream.Seek(0, SeekOrigin.Begin);


                    var buffer = new byte[1000];


                    reader.Read(buffer, 0, buffer.Length);


                    base64String = Convert.ToBase64String(buffer);
                    Console.WriteLine( base64String);

                }
            }

but my program shows
AAABlAAAAGQAAAAMAAAAAQAB3esBMwYQ/////wAAAAAAAAAAAAAAAAAAAAAgNS43ATFVsklOVEVMIE5UICAgIGJhdGNoX2pvRlVMTCAgICAuMSAgYm9zICAgICAgICAgAAAAAAAAAAAAAAAAAABAAAACxwoAAAAMAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAATWFzcz0xNTAgZmhlaWdodD00LjM3MDk5ODY1IGltcGFjdDAgTExkYW1wIDEgTFlkYW1wIDAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAAAAAAAAAscKAAAAAAAAAAAACfvxAAABlAAAAKQAAAAoAAAADAAAAAoAAAAKAAAD6AAAAAYAAAALAAAACwAAAAAAAABPAALHCgAAALYAAAiJAAAQXAAAAKgAAACbAAAcFwAAAAAAAAAAAAAAAP////8AAAABAAAAAAACxwoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAKQAAAAcAAAABgAAAAEAAAACAAAAAwAAAAQAAAAFAAAABgAAABwAAAAsAAAACgAAAAgAAAAHAAAAAgAAAAEAAAAFAAAABAAAAAMAAAAGAAAACQAAAAoAAAAsAAAAMAAAAAsAAAABAAAAAgAAAAMAAAALAAAACAAAAAkAAAAKAAAABAAAAAUAAAAGAAAABwAAADAAAB9EAAAH0AAAITkAACnGAAAyUwAAOuAAAENtAABL+gAAVIcAAF0UAABloQAAbi4AAHa7AAB/SAAAh9UAAJBiAACY7wAAoXwAAKoJAACylgAAuyMAAMOwAADMPQAA1NQAAN1rAADmAgAA7pkAAPcwAAD/xwABCF4AARD1AAEZjAABIiMAASq6AAEzUQABO+gAAUR/AAFNFgABVa0AAV5EAAFm2wABb3IAAXgJAAGAoAABiTcAAZHOAAGaZQABovwAAauTAAG0KgABvMEAAcVYAAHN7wAB1oYAAd8dAAHntAAB8EsAAfjiAAIBeQACChAAAhKnAAIbPgACI9UAAixsAAI1AwACPZoAAkYxAAJOyA==

File stores data in such format:
DUMP OF FILE= D:\batch_job.rst
RECORDS 1 TO 1000000




RECORD= 1 LENGTH= 100 LOC= 0 KBF= 100 (HEADER RECORD)
SOURCE: ANSYS PROGRAM
UNIT: 12 FILE FORMAT: External
RECORD LENGTH: 16384 FILE SIZE: 182026 SPLIT POINT: 32768
CREATION TIME: 12:23:47
CREATION DATE: 11/04/2012
RELEASE: 5.7.1 UPDATE: 20010418


SYSTEM: INTEL NT
PRODUCT NAME: FULL
JOBNAME(1:8): batch_jo
JOBNAME(1:32):
USER: bos


TITLE: Mass=150 fheight=4.37099865 impact0 LLdamp 1 LYdamp 0
SUBTITLE:


UNITS: UNDEFINED



Help me with this question.Thank you.
 
Last edited by a moderator:

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
3,136
Location
Sydney, Australia
Programming Experience
10+
I'm not sure what you expected when you converted the data to a base-64 string. You say that it's a binary file but is it really? Is what you have shown, i.e.
RECORD= 1 LENGTH= 100 LOC= 0 KBF= 100 (HEADER RECORD)
SOURCE: ANSYS PROGRAM
UNIT: 12 FILE FORMAT: External
RECORD LENGTH: 16384 FILE SIZE: 182026 SPLIT POINT: 32768
CREATION TIME: 12:23:47
CREATION DATE: 11/04/2012
RELEASE: 5.7.1 UPDATE: 20010418


SYSTEM: INTEL NT
PRODUCT NAME: FULL
JOBNAME(1:8): batch_jo
JOBNAME(1:32):
USER: bos


TITLE: Mass=150 fheight=4.37099865 impact0 LLdamp 1 LYdamp 0
SUBTITLE:


UNITS: UNDEFINED
actually what's in the file? If so then that looks rather like text to me so it's a text file and should be read as such, i.e. using a StreamReader. Can you actually read the file if you open it in Notepad?
 
Top Bottom