Showing posts with label I/O. Show all posts
Showing posts with label I/O. Show all posts

Scanner Troubles

I got ahold of this text file that was the content of the ZF05 zine. My goal was to write a program to extract the good parts of the zine for me to read quickly. Of course I was writing my program in Java.

My process was to do some Test Driven Development. So before I wrote the complex algorithms to do smart filters, I decided to write some simple I/O operations first. To do this I employed the Scanner class in Java. That should be easy. You pass the Scanner constructor a File object. Then you keep calling nextLine() as long as there is a hasLine().

My first TDD exercise was to write a copy program. It should just take a file and duplicate its contents to a second file. That sounds easy. My first attempt compiled quickly. But when it ran, it only copied part of the file. I thought perhaps it was some type of buffer overflow. However no exceptions were through. The program ended gracefully. I put my debugger hat on. Then I determined how far the copy was getting in the source file. That when I discovered some strange characters in the source file. They seemed to be causing hasLine() to return FALSE prematurely. It is going to take some digging into the Scanner class to figure out why I was getting this false positive. For now I will just give you some lines around the place where hasLine() choked. See if you can see why it is failing:

-rw-r--r-- 1 thalakan thalakan 386 Jan 5 2006 zeller.cd
rwxr-xr-x 2 thalakan thalakan 512 Jun 22 2006 かたかã�ls
$ cat watcher.pl
#!/usr/bin/perl -w

Missing Arrays

I am halfway through my college class on Java. There are a number of topics we have not covered yet. Normally that is fine, as we will eventually get to them. However I just entered a programming contest to write a Java game in 7 days. My game will be called dL1.

We have yet to cover packages, arrays, or file input/output. That is a bummer. My game will be on a two dimensional grid. That's where arrays would really come in handy. My plan is to substitute objects that references each other for arrays.

I was hoping to use some third party code to do the actual drawing for my game. So I cannot wait any more. I am reading ahead in my course book to see how to use packages. As of last night, I still had not mastered the topic. I really need to get a move on it. The contest ends in 7 days and I have one Java file which does not compile. May the Force be with me.