日期:2014-05-18  浏览次数:20542 次

急!!关于客户端进行文件的提交
在做blog系统时遇到的这个问题,我一开始单纯的认为文件的提交不过就要到java里的IO流读写,但那只能在本机上实现,放在B/S上就完全不一样了。主要是不知道客户端用什么地址。
劳烦了!
急!

------解决方案--------------------
是上传文件
------解决方案--------------------
是上传文件吗
------解决方案--------------------
在google搜索一下文件上传,很多例子的
------解决方案--------------------
SmartUpLoad能实现
------解决方案--------------------
import java.net.*;
import java.io.*;
public class Server
{
private ServerSocket server;
private Socket you;
private receive rec;
public Server()
{
try
{
server = new ServerSocket(2007);
System.out.println( "服务器运行中,监听端口:2007...... ");
while(true)
{
you = server.accept();
if(you != null)
{
System.out.println( "有客户连接启动接收线程... ");
new Thread(new receive(you)).start();
System.out.println( "接收文件内容如下: ---> 服务器继续监听中... ");
}
}
}catch(Exception e){System.out.println( "服务端运行出错! ");}
}

public static void main(String args[])
{
new Server();
}
}

class receive implements Runnable
{
private File files;
private DataInputStream din = null;
private DataOutputStream dout = null;
private Socket mySock = null;
private int str = 1;
public receive(Socket you)
{
this.mySock = you;
//files = new File( "d:\\data.txt ");
}

public void run()
{
try
{
din = new DataInputStream(mySock.getInputStream());
dout = new DataOutputStream(mySock.getOutputStream());

while(true)
{
if((str=din.readInt()) == 0)
break;
System.out.println( " " + din.readUTF());
}
clears();
}catch(Exception e){System.out.println( "接收出错! ");}
finally
{
clears();
}

}

void clears()
{
try
{
dout.close();
din.close();
mySock.close();
}catch(Exception e){System.out.println( "关闭出错 ");}
}

}
------解决方案--------------------
不知道客户端用什么地址?
是什么意思,不知道上传的文件的存储地址还是?