hor*_*HAY 0 java sockets outputstream
正如标题所说,得到错误"outputsteam是抽象的".我是Java的新手,所以不太确定如何解决它.我的程序正在尝试使用此代码将套接字上的连接的arraylist发送到客户端;
public void sendList(Socket clientSocket, ArrayList connections) throws IOException
{
OutputStream outputStream = new OutputStream(clientSocket.getOutputStream(), true);
ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream);
objectOutputStream.writeObject(connections);
System.out.println("List sent");
}
Run Code Online (Sandbox Code Playgroud)
提前致谢!
错误消息告诉您确切的错误:您不能在抽象类上调用构造函数,而是必须启动OutputStream的具体子类之一.也许是一个包装你的clientSocket OutputStream的BufferedOutputStream.
为什么你甚至有这条线?
OutputStream outputStream = new OutputStream(clientSocket.getOutputStream(),
true);
Run Code Online (Sandbox Code Playgroud)
为什么不直接使用来自clientSocket的OutputStream呢?