Formatting Output
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   jignesh_gohel
Posted On:   Saturday, March 5, 2005 09:08 PM

hello, I'm making a client-server program in which i'm sending a String from client side using DataOutputStream & receiving it on the Servervside using the following code: InputStream in = request.getInputStream(); BufferedReader r = new BufferedReader(new InputStreamReader(in)); StringBuffer buf = new StringBuffer(); String line; while ((line = r.readLine())!=null) { buf.append(line); } String s = buf.toString(); But in the output i'm receiving is appended with the "+" operator.What i should do If i want to print the String in the same manner as I sent it,i.e. with   More>>


hello,

I'm making a client-server program in which i'm sending a String from client side using DataOutputStream & receiving it on the Servervside using the following code:


			

InputStream in = request.getInputStream();

BufferedReader r = new BufferedReader(new
InputStreamReader(in));

StringBuffer buf = new StringBuffer();

String line;

while ((line = r.readLine())!=null)
{
buf.append(line);
}

String s = buf.toString();





But in the output i'm receiving is appended with the "+" operator.What i should do If i want to print the String in the same manner as I sent it,i.e. without the concatenation operator?




Thanking you ,
Jignesh    <<Less

Re: Formatting Output

Posted By:   Stephen_Ostermiller  
Posted On:   Friday, March 11, 2005 12:56 AM

I'm suspicious of the DataOutputStream. Is there any reason that you are using it as opposed to a BufferedOutputStream?


Since you are sending character data (strings) you probably also want to pay attention to character encoding.


Client:


PrintWriter out = new PrintWriter(
new BufferedWriter(
new OutputStreamWriter(
getOutputStream(),
"UTF-8"
)
)
);
out.println("My Line");
out.flush();


Server:

BufferedReader r = new BufferedReader(
new InputStreamReader(in, "UTF-8")
);
String line;
while ((line = r.readLine())!=null){
buf.append(line);
}
String s = buf.toString();
About | Sitemap | Contact