Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Problem With File IO-- Double-Spacing in Text File?
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
ihsh




PostPosted: Sun Feb 19, 2012 11:58 pm   Post subject: 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:

Quote:
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 unofficial CCC solution page have no problem reading the text files (they use a special file-reading method provided by the HSA console class).

So my question is: is this my problem or the file's problem (or both)? I use the following way to read input:
Java:

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? Confused



s5.txt
 Description:

Download
 Filename:  s5.txt
 Filesize:  54 Bytes
 Downloaded:  79 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
DemonWasp




PostPosted: Mon Feb 20, 2012 1:53 am   Post subject: 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




PostPosted: Mon Feb 20, 2012 10:41 am   Post subject: RE:Problem With File IO-- Double-Spacing in Text File?

i didnt think .txt files COULD be double-spaced, so its probably both
ihsh




PostPosted: Mon Feb 20, 2012 10:42 am   Post subject: 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)... Sad
mirhagk




PostPosted: Mon Feb 20, 2012 12:05 pm   Post subject: 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]




PostPosted: Mon Feb 20, 2012 8:53 pm   Post subject: Re: Problem With File IO-- Double-Spacing in Text File?

ihsh @ 2012-02-20, 10:42 am wrote:
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)... Sad

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.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: