Nick Tsui
Nick Tsui

Reputation: 634

FileHelper reading csv file freezing

I am trying to use FileHelper to read a csv file, in which data are arranged like this: 0,0,0,0,0,0,0,1,1,1,0,0,0,0,...... 1kX1k of them. Here is my FileHelper code:

[DelimitedRecord(",")] 
    public class ROIMaskCSV 
    { 
        public int value;

        //[TransformToRecord(typeof(ROIMaskCSV[]))]
        public static ROIMaskCSV[] loadMask(string fileName)
        {

            DelimitedFileEngine engine = new DelimitedFileEngine(typeof(ROIMaskCSV));

            ROIMaskCSV[] mask = (ROIMaskCSV[])engine.ReadFile(fileName); 

           // mask[0].value = this.value;

            return mask;
        }
    }

And here is where FileHelper loadMask() function gets called:

public class TIFFIImageIO
{
    public static int LoadTIFF(string fileName, int x, int y)
    {

        ROIMaskCSV[] mask = ROIMaskCSV.loadMask("d:\\myMask.csv");
        ......

I stepped in, so when program gets:

 ROIMaskCSV[] mask = (ROIMaskCSV[])engine.ReadFile(fileName); 

the program is just freezed. I am not sure what happened. Something I did wrong? Anyone can give some pointers? Any suggestion is appreciated.

Upvotes: 0

Views: 622

Answers (1)

Nick Tsui
Nick Tsui

Reputation: 634

OK. I give up. I will just stream read the file, then parse it. This is the code I read my csv file:

byte[] array = System.IO.File.ReadAllBytes(fileName);

Then convert array[i] to char/int, or whatever type you want.

To char, for example to convert ASC II 65 to 'A':

char.ConvertFromUtf32(65);

To int, for example to convert ASC II 48 to 0:

Convert.ToInt32(char.ConvertFromUtf32(48));

Upvotes: 2

Related Questions