Centos系统中Socket中文乱码

服务器

Socket clntSock = servSock.accept();
				SocketAddress clientAddress = clntSock.getRemoteSocketAddress();
				System.out.println("Handling client at " + clientAddress);

				// b,使用所返回的Socket实例的InputStream和OutputStream与客户端进行通信
				InputStream in = clntSock.getInputStream();
				BufferedReader rdr = new BufferedReader(new InputStreamReader(in,"UTF-8"));
				String line = rdr.readLine();
				System.out.println("从客户端来的信息:" + line);
				hw.ReadText(line, 1);
				clntSock.close();

 客户端:

 Socket socket = new Socket("xxxx", 5567);
	           OutputStream os =  socket.getOutputStream();  
//	            DataOutputStream bos = new DataOutputStream(os);  
//	            byte[] fullByte1 = new String("您好看起来很棒".getBytes()).getBytes("UTF-8");  
//	            byte[] fullByte1 = new String("您好".getBytes(), "UTF-8").getBytes("GBK");
//	            bos.write(fullByte1);
//	            bos.flush();  
	           OutputStreamWriter outSW = null; 
	           outSW = new OutputStreamWriter(os, "UTF-8");  
	            BufferedWriter bw = new BufferedWriter(outSW);  
	            bw.write("您好测试");
	            bw.close();
	            os.close();
	           // 关闭输入流
	            bw.close();
	            outSW.close();
//	            dataOS.close();
	            os.close();

 

你可能感兴趣的:(Centos系统中Socket中文乱码)