import java.io.*;
import java.net.*;
import java.net.*;
import java.io.*;
public class DataClient {
public static final int SERVICE_PORT = 1500;
public static final int DATA_SIZE = 1024;
public static void main(String[] args) {
String hostName="10.100.100.100";
String filePath="C:"+File.separatorChar+"電話號碼_Tel.xls";
try{
Socket client = new Socket(hostName,SERVICE_PORT);
System.out.println("Connection established");
System.out.println(client.getRemoteSocketAddress());
client.setSoTimeout(2000);
File file=new File(filePath);
if(file.exists()){
file.delete();
System.out.println("Create new file");
}
InputStream in = client.getInputStream();
BufferedReader readerFile = new BufferedReader(
new InputStreamReader(in));
DataInputStream reader = new DataInputStream(in);
FileOutputStream fos = new FileOutputStream(file);
String filename=readerFile.readLine();
System.out.println("FileName:---------->>>>>>" + filename);
byte[] bs = new byte[DATA_SIZE];
int length;
System.out.println("Data receiving started");
while( (length=reader.read(bs)) != -1){
fos.write(bs,0,length);
bs = new byte[DATA_SIZE];
Thread.sleep(200);
}
System.out.println("Receiving completed");
readerFile.close();
reader.close();
fos.close();
}catch(Exception e){
e.printStackTrace();
}
}
}