• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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
 
Oh the stink of it! Smell my tiny ad!
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic