• 手机版

    扫码体验手机版

  • 微信公众号

    扫码关注公众号

国内首家协议开发

软芯音视解码保护平台

在线
客服

发布
需求

在线
聊天

天盟
APP

天盟APP下载

关注
微信

微信扫一扫访问
顶部

readUTF报错 connection reset

public class TClient {
        public static void main(String[] args) throws UnknownHostException, IOException {
//从磁盘上读,输入流 字节流
                InputStream is=new FileInputStream("d:/zz.txt");
                //写到管道中
                Socket client=new Socket("localhost", 8000);
                OutputStream os=client.getOutputStream();
                //边读边写 while 因为我们不知道文件的大小
                int len=is.read();//初始变化量 文件末尾是-1
                while(len!=-1){
                        os.write(len);
                        len=is.read();
                }
                client.shutdownOutput();
                //接收服务器响应
                DataInputStream dis=new DataInputStream(client.getInputStream());
                System.out.println(dis.readUTF());       
                client.shutdownInput();
                //关闭
                dis.close();
                os.close();
                is.close();
                client.close();
        }
}
client端
public class TServer {
        public static void main(String[] args) throws IOException {


                //从管道内读数据
                ServerSocket server=new ServerSocket(8000);
                //监听
                Socket client=        server.accept();
                //接收客户端socket中流的数据 对服务器来说 就是输入流
                InputStream is=        client.getInputStream();
                //写到磁盘上
                OutputStream os=new FileOutputStream("kk.txt");
                int len=0;
                while((len=is.read())!=-1){
                        os.write(len);
                }
                client.shutdownInput();
                //服务器给客户端一个响应
                DataOutputStream dos=new DataOutputStream(client.getOutputStream());
                 dos.writeUTF("上传成功");
                 client.shutdownOutput();
                //关闭流
                 dos.close();
                 os.close();
                 is.close();
                 client.close();
                 server.close();
               
        }
       
}
094003uic3vi77vbfepvu7.jpg

免责声明:本内容仅代表回答会员见解不代表天盟观点,请谨慎对待。

版权声明:作者保留权利,不代表天盟立场。

使用道具 举报

发新帖

发布任务需求已有1031167位用户正在使用天盟网服务

发布分类: *
任务预算: *
需求内容: *
手机号码: *
任务商家报价为
  • 预算价 :
  • 成交价 :
  • 完工期 :
  • 质保期 :

* 最终任务项目以服务商报价、双方协商为准!