public static void main(String[] args) {
try {
Socket socket = new Socket(InetAddress.getByName("127.0.0.1"), 10010);
OutputStream out = socket.getOutputStream();
Scanner scanner = new Scanner(System.in);
File file = null;
while (true) {
System.out.println("Please put in the name of file:");
String fileName = scanner.nextLine();
file = new File(fileName);
PrintWriter pw = new PrintWriter(out, true);
pw.println(file.getName()); //发送文件名
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
BufferedOutputStream bos = new BufferedOutputStream(out);
byte[] buf = new byte[1024*16];
int len;
while (-1 != (len = bis.read(buf))) {
bos.write(buf, 0, len);
bos.flush();//注意这里一定要刷新,要不然数据没有出缓冲区。更谈不上发送了
}
socket.shutdownOutput();
BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
System.out.println(br.readLine());