Well.. Based on the available choices. 2 will be appropriate But linenumberreader may help to readline() as a single string object... Ragu
Valentin Crettaz
Gold Digger
Sheriff
Joined: Aug 26, 2001
Posts: 7610
posted
0
Hi guys, I'd just like to remember you one thing, the questions says "A file is going to be read one line at a time..." So the only correct answer can be either 4 or 5 since readUTF of DataInputStream only returns a String object and not a whole line. BufferedReader has a readLine method which can achieve what is asked. Now, we have to choose between 4 and 5 and it's not very difficult since the encoding 8859_1 does not exist (ISO-8859-1 does though) So the correct answer should be 4. Note: LineNumberReader is a subclass of BufferedReader... The solution you gave is correct but not necessary since BufferedReader already provides all constructs necessary to fulfill what is asked... HIH ------------------ Valentin Crettaz Sun Certified Programmer for Java 2 Platform [This message has been edited by Valentin Crettaz (edited November 16, 2001).]
Originally posted by Valentin Crettaz: Hi guys, I'd just like to remember you one thing, the questions says "A file is going to be read [b]one line at a time..." So the only correct answer can be either 4 or 5 since readUTF of DataInputStream only returns a String object and not a whole line. BufferedReader has a readLine method which can achieve what is asked. Now, we have to choose between 4 and 5 and it's not very difficult since the encoding 8859_1 does not exist (ISO-8859-1 does though) So the correct answer should be 4. Note: LineNumberReader is a subclass of BufferedReader... The solution you gave is correct but not necessary since BufferedReader already provides all constructs necessary to fulfill what is asked... HIH [/B]
Thankx Val... Good to see your msg once in a while... Here is my thought. My choice is 2 is not based readUTF()... method But becoz of readLine() method... Since this method is implemented from DataInput interface... But the preferred way is what you had mentioned choice 4 since readLine() is deprecated.... So I wont agree totally and rule out that choice 2 is wrong... just that it may not be preferred way of doing it
Thankyou Ragu
Valentin Crettaz
Gold Digger
Sheriff
Joined: Aug 26, 2001
Posts: 7610
posted
0
Hi Ragu, Again the question says "Which construction is most suitable for reading the file ?" As you pointed out readLine in DataInputStream is deprecated and there is a note in the API stating that a preferred way is to use BufferedReader.readLine(). Again, the most suitable choice here in this very question is 4 and not 2, do you agree ? I mean there is no other choice if you want to fully comply with the wording of the question. ------------------ Valentin Crettaz Sun Certified Programmer for Java 2 Platform
Ragu Sivaraman
Ranch Hand
Joined: Jul 20, 2001
Posts: 464
posted
0
Originally posted by Valentin Crettaz: Hi Ragu, Again the question says "Which construction is [b]most suitable for reading the file ?" As you pointed out readLine in DataInputStream is deprecated and there is a note in the API stating that a preferred way is to use BufferedReader.readLine(). Again, the most suitable choice here in this very question is 4 and not 2, do you agree ? I mean there is no other choice if you want to fully comply with the wording of the question. [/B]
"most suitable" Key point... Thankx Val As long as your are here in javaranch, I always feel I will get a correct response :-) Have fun Ragu
Valentin Crettaz
Gold Digger
Sheriff
Joined: Aug 26, 2001
Posts: 7610
posted
0
Originally posted by Ragu Sivaraman: As long as your are here in javaranch, I always feel I will get a correct response :-) Have fun Ragu
What a compliment ! Thanx You have fun too !
------------------ Valentin Crettaz Sun Certified Programmer for Java 2 Platform
Salamina Daniel
Ranch Hand
Joined: Oct 10, 2001
Posts: 41
posted
0
Thanks a lot for your answers. Really helped me clarify my mind. Indeed BufferedReader has a readLine() method that will do the job. Best regards
Jan Andersson
Greenhorn
Joined: Nov 19, 2001
Posts: 5
posted
0
Are there any difference between these two:
------------------ /jan [This message has been edited by Jan Andersson (edited November 19, 2001).]
/jan
Valentin Crettaz
Gold Digger
Sheriff
Joined: Aug 26, 2001
Posts: 7610
posted
0
with the first you can specify an encoding to usr when reading the stream while with the second the encoding defaults to the platform encoding. HIH ------------------ Valentin Crettaz Sun Certified Programmer for Java 2 Platform [This message has been edited by Valentin Crettaz (edited November 19, 2001).]