前景提要
HDC调试需求开发(15万预算),能者速来!>>>
java.net.SocketException: Software caused connection abort: socket write error
就是这个异常,我这个只是个练习,就想知道为什么传递一个大一些的文件就抛出这个异常
服务器端代码
public static void main(String[] args) throws IOException { ServerSocket ss = new ServerSocket(); InetSocketAddress inetaddress = new InetSocketAddress("localhost",9900); ss.bind(inetaddress); Socket sk = ss.accept(); InputStream input = sk.getInputStream(); int available= input.available(); System.out.println(available); sk.close(); ss.close(); }
客户端代码
public static void main(String[] args) { Socket sk=null; try { InetAddress id = InetAddress.getByName("localhost"); System.out.println(id.getHostAddress()); sk = new Socket(id,9900); } catch (UnknownHostException e1) { e1.printStackTrace();
} catch (IOException e1) { e1.printStackTrace(); } try { System.out.println(sk.getSendBufferSize()); OutputStream out = sk.getOutputStream(); FileInputStream input = new FileInputStream("F:/E.java"); byte bs [] = new byte[input.available()]; input.read(bs); input.close(); out.write(bs); out.flush(); out.close(); } catch (IOException e) { e.printStackTrace(); } }
E.java这个文件一但大了 就会抛出异常!