简体   繁体   中英

PrintWriter vs BufferedWriter

I'm trying to transfer strings from my server to my client and I'm trying to find an explanation why when I'm using PrintWriter in my server the client receives the string while when I'm using BufferedWriter the client doesn't receive the string.

In my client I have the next readers/writers:

out=new PrintWriter(s.getOutputStream());
in=new BufferedReader(new InputStreamReader(s.getInputStream()));

In my main I'm receiving data from server with the next call:

String sol=in.readLine();

In my server I'm sending data with the next call (os is an outputStream that I get in my function):

PrintWriter out= new PrintWriter(os);
out.write("test");
out.flush();

While when I use BufferedWriter it doesn't send data to the client (or the client can't receive it?) "

BufferedWriter out = new BufferedWriter(new OutputStreamWriter(os));
out.append("test"); // tried also using out.write
out.flush();  

On my server side Bufferwriter doesn't add "\\n" to the end of the string while in my client side I'm trying to read a line with inputstream. Printwriter adds "\\n" in the method println. Thanks to @EdwinDalorzo for the help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM