[英]How to convert from getInputStream to DataInputStream
I've got a java proxy and I just need to convert from using getInputStream and start using DataInputStream. 我有一个Java代理,我只需要从使用getInputStream进行转换就可以开始使用DataInputStream。
This is the code to start the stream. 这是启动流的代码。
private Socket socket;
private static OutputStream os;
private InputStream is;
private byte[] request = new byte[1024];
public Client(Socket clientSocket) throws IOException {
socket = clientSocket;
is = socket.getInputStream();
os = socket.getOutputStream();
Log.logInfo("* Client connected");
}
What do I need to change from that? 那我需要改变什么?
Thanks! 谢谢!
尝试这个:
DataInputStream streamIn = new DataInputStream(new BufferedInputStream(is));
What about using a DataInputStream constructor. 如何使用DataInputStream构造函数。 Using the constructor you can covert easily a InputStream to a DataOutputStream.
使用构造函数,您可以轻松地将InputStream转换为DataOutputStream。
Now You have the InputStream is
which you have get from the socket.getInputStream()
method. 现在你已经InputStream的
is
,你必须从一开始socket.getInputStream()
方法。 You can construct your DataOutputSTream
using the following code snippet - 您可以使用以下代码段构建
DataOutputSTream
DataOutputStream dataOutputStream = new DataOutputStream(is);
Hope it will help. 希望它会有所帮助。
Thanks 谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.