📄 xmlsendtest.java
字号:
package portal.collector;
/*
*@author Wang Zi Juan
*/
import java.io.*;
import java.net.*;
public class XmlSendTest{
public static void SendXml()throws Exception{
//创建文件流用来读取文件中的数据
File file=new File("ggroup.xml");
FileInputStream fos=new FileInputStream(file);
//已知接收服务器地址及端口,创建socket连接,准备发送文件
//byte[] b = {(byte)10, (byte)64, (byte)0, (byte)20};//目录服务器地址
//InetAddress addr = InetAddress.getByAddress(b);
//InetAddress addr = InetAddress.getByAddress(Test.directoryAdd);
//Socket send = new Socket(addr,Test.directoryport); //创建socket 准备向目录服务发送xml文件
Socket send = new Socket("127.0.0.1",8086);
//创建网络输出流并提供数据包装器
OutputStream netOut=send.getOutputStream();
OutputStream doc=new DataOutputStream(new BufferedOutputStream(netOut));
//创建文件读取缓冲区
byte[] buf=new byte[2048];
int num=fos.read(buf);
while(num!=(-1)){//是否读完文件
doc.write(buf,0,num);//把文件数据写出网络缓冲区
doc.flush();//刷新缓冲区把数据写往客户端
num=fos.read(buf);//继续从文件中读取数据
}
fos.close();
doc.close();
System.out.println("send over!");
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try
{
XmlSendTest.SendXml();
}catch(Exception e) {
System.out.println(e);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -