posted 23 years ago
Hi-
This is from Kai's notes:
Connect to a socket s read one line of ASCII char. Please construct the right input method:
1) InputStream in = new InputStream(s.getInputStream());
2) DataInputStream in = new DataInputStream(s.getInputStream());
3) BufferedReader in = new BufferedReader(InputStreamReader(s.getInputStream());
4) BufferedReader in = new BufferedReader(InputStreamReader(s.getInputStream(), "8859_1");
I believe 2 & 3 are the correct choices. Both classes have readLine(). Answer 4 is incorrect because the "8859_1" should be "ISO-8859-1". Answer 1 is incorrect because an InputStream cannot read lines and it does not have such a constructor.
Is this correct? I'm confused about character encodings when it comes to reading ascii characters, does it matter whether the encoding is ISO-8859-1 or the platform default. And with this phrasing of the question is DataInputStream also a correct choice?