• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

socket read ASCII char

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Almost the same question at http://www.javaranch.com/ubb/Forum24/HTML/013222.html with some answers...
HIH
------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic