
-----------------------------------
ihsh
Sun Feb 19, 2012 11:58 pm

Problem With File IO-- Double-Spacing in Text File?
-----------------------------------
When testing my solution for CCC 2008 s5 (nukit), my program kept crashing when it was still reading the input from the text file. 
Then, after tweaking with my program for ten minutes, I realized that the text file seemed to be double-spaced. That is, when my program reads the file, there is one extra empty line in between every line of input. And if I just copy the content of the file into this post-editor, it is double spaced too:

5

8 7 8 4

7 7 7 8

8 8 8 8

7 8 7 7

8 0 8 8


What's even stranger is that the solutions provided by the
BufferedReader in = new BufferedReader (new FileReader ("s5.txt"));
num = Integer.parseInt (input.readLine ());
...



Also, will I have to worry about this when I am writing the CCC?  :?

-----------------------------------
DemonWasp
Mon Feb 20, 2012 1:53 am

RE:Problem With File IO-- Double-Spacing in Text File?
-----------------------------------
The method you show won't handle multiple integers per line, no matter what you do. You should read up on the Scanner class, which is designed to make this kind of thing easy: http://docs.oracle.com/javase/6/docs/api/java/util/Scanner.html

-----------------------------------
evildaddy911
Mon Feb 20, 2012 10:41 am

RE:Problem With File IO-- Double-Spacing in Text File?
-----------------------------------
i didnt think .txt files COULD be double-spaced, so its probably both

-----------------------------------
ihsh
Mon Feb 20, 2012 10:42 am

Re: Problem With File IO-- Double-Spacing in Text File?
-----------------------------------
Hmm, somehow I can't use the Scanner class with the IDE that I use at home and at school, which is Ready To Program by Holts Software (and it uses java 1.4.2)...  :(

-----------------------------------
mirhagk
Mon Feb 20, 2012 12:05 pm

RE:Problem With File IO-- Double-Spacing in Text File?
-----------------------------------
A text file is double spaced just by having 2 newline characters. Likely there's a /r/n incompatibility for something like this.

-----------------------------------
[Gandalf]
Mon Feb 20, 2012 8:53 pm

Re: Problem With File IO-- Double-Spacing in Text File?
-----------------------------------
Hmm, somehow I can't use the Scanner class with the IDE that I use at home and at school, which is Ready To Program by Holts Software (and it uses java 1.4.2)...  :(
The Scanner class was introduced in Java 1.5.  I suggest, if at all possible, that you get set up and familiar with a more modern version of the Java SDK - it'll make solving problems easier.
