Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

input/output

 
sheri
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

hi
1:Connected to a socket s, read one line of ASCII char. Please construct the right input method:
- InputStream in = new InputStream(s.getInputStream());
- DataInputStream in = new DataInputStream(s.getInputStream());
- BufferedReader in = new BufferedReader(InputStreamReader(s.getInputStream());
- BufferedReader in = new BufferedReader(InputStreamReader(s.getInputStream(), "8859_1");
Use socket method. "in" is an InputStream constructed by "InputStream in = new Socket().getInputStream();"
2: Which constructor is the most adequate for transmition of ASCII data from the socket?
- BufferedReader(InputStreamReader(in, "8859_1")) // his choice
- BufferedReader(InputStreamReader(in))
- DataInputStream(in)
- BufferedInputStream(DataInputStream(in))
- InputStreamReader(in)
3:You want to use the readLine() method which of the following will be the correct initialization?
a) BufferedReader bf = new BufferedReader(new InputStreamReader(new FileInputStream("file","8859_1")))
b) BufferedReader bf = new BufferedReader(new InputStreamReader(new FileInputStream("file")))
c) DataInputStream ds = new DataInputStream(new FileInputStream("file"))

4:What kind of Stream does DataInputStream accept?
what are the valid type of arguments for different types of streams & readers/writers...
can anybody ans these question.i am totally confused when i get these type of questions...
can anybody help with this..(any notes on this topic)so that i can read..& be ready for the exam..
thanx
sherinn
 
Mapraputa Is
Leverager of our synergies
Sheriff
Posts: 10065
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here is one link: http://www.geocities.com/SiliconValley/Network/3693/java_cert.html
 
Ramesh Donnipadu
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Answer to Qn1.
-There is no readLine() method in InputStream.
-readLine() method is deprecated in DataInputStream.
-unbalanced parentheses and Argument to BufferedReader() is not correct.
-same as above.
The Correct answer I believe should be something like this.
BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
Or
BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()),"8859-1");
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am transferring this post to I/O and Streams forum
Ajith
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic