日期:2014-05-20 浏览次数:20903 次
package cn.dzr.uploadapp;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;
public class UploadClient
{
public static void main(String[] args) throws IOException
{
/*
*/
System.out.println("客服端开始启动.......");
Socket s = new Socket(InetAddress.getLocalHost(),10005);
File file = new File("D:"+File.separator + "Client/Client.txt");
FileInputStream fs = new FileInputStream(file);
//该流用于从字符串读取数据
BufferedReader bufr = new BufferedReader(new InputStreamReader
(fs));
// System.out.println(file.canRead());
// System.out.println(file.canWrite());
// System.out.println(file.canExecute());
// System.out.println(file.toURI());
//该流用于将数据传输到socket流中.
BufferedOutputStream out = new BufferedOutputStream(new
DataOutputStream(s.getOutputStream()));
PrintWriter pw = new PrintWriter(s.getOutputStream());
String str = null;
P(System.currentTimeMillis());
while((str =bufr.readLine())!=null)
{
out.write(str.getBytes());
pw.println(str);
}
P(System.currentTimeMillis());
pw.close();
out.close();
bufr.close();
fs.close();
s.close();
}