Monday, July 28, 2008

C# : Reading a binary file

I needed to read a file into a buffer for subsequent encoding.

Made the mistake of usuing TextReader which of course has issues becaise the EOF could be anywhere for a bionary file. Also you don't know how big the file is and you don't want to use Peek and read one character at a time.

Came up with the following:



...

try
{
// Note: This is a binary file so can't use EOF

FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);

byte[] bArray = new byte[br.BaseStream.Length];
bArray = br.ReadBytes(Convert.ToInt32(br.BaseStream.Length));
return bArray;
}

catch (Exception ex)
{
...
}



Enjoy!

Misc : Error 0X80070052 on USB Flash Drives

I came across this at the weekend.

Trying to copy some files from a DVD to a flash drive and kept getting this error.

Tried everything - reformatted etc. but no joy.

So Mr. Google to the rescue.

One link suggested that the problem was that there is a limit to the number of files you can copy to the root directory of a USB drive.

Sounded suspect but made a folder under root and then copied the files to the folder.

Suddenly everything worked!

Amazing!

Enjoy!

Monday, July 07, 2008

Eclipse : Compiling JVM 1.4 with Eclipse Europa

Eclipse Europa won't work with anything less than JVM 1.5.

But what happens if your client needs a Java 1.4 program? Do you have to download an earlier version of Eclipse?

Actually - no!

You can compile 1.4 programs inside the Europa 1.5 workspace.

Under "Windows - Preferences - Java - Installed JREs", you need to add the path to the 1.4 JVM.

Right click on the 1.4 project.

Under "Properties - Java Build Path - Libraries", ensure that the JRE System Library points to the 1.4 version.

Under "Properties - Java Compiler", click "Enable project specific settings". Set "Compiler compliance level" to 1.4.

That's it.

Enjoy!