public static void sendMsg(String url,int port) throws Exception{
int size=0,length=0;
Socket s = null;
OutputStream os = null;
InputStream is = null;
FileInputStream fis = null;
try {
s = new Socket("localhost",port);
os =s.getOutputStream();
is = s.getInputStream();
File sendFile = new File(url);
fis = new FileInputStream(sendFile);
byte[] buffer = new byte[1024*5];
int i=0;
while((size=is.read(buffer))!=-1){
System.out.println(size+" ");
os.write(buffer,0,size);
os.flush();
System.out.println("第"+ ++i+"次输出");
}
} catch (IOException e) {
e.printStackTrace();
}finally{
is.close();
fis.close();
os.close();
s.close();
int size=0,length=0;
Socket s = null;
OutputStream os = null;
InputStream is = null;
FileInputStream fis = null;
try {
s = new Socket("localhost",port);
os =s.getOutputStream();
is = s.getInputStream();
File sendFile = new File(url);
fis = new FileInputStream(sendFile);
byte[] buffer = new byte[1024*5];
int i=0;
while((size=is.read(buffer))!=-1){
System.out.println(size+" ");
os.write(buffer,0,size);
os.flush();
System.out.println("第"+ ++i+"次输出");
}
} catch (IOException e) {
e.printStackTrace();
}finally{
is.close();
fis.close();
os.close();
s.close();
}
期中
String url = "//home//test//my//cache//1.odc";
port::对应端口