<input type='file' name='upfile' size=20>
<input type='submit' value='上传文件'/>
</form>
<?php
echo $_FILES['upfile']['name']
?>
代码如下。。。我测试过了。。。。下面两个类是在同一台机器上进行测试的,先运行Server.java,再运行Client.javaimport java.io.*
import java.net.*
import java.text.SimpleDateFormat
import java.util.Date
public class Server {
public static void main(String[] args) throws Exception{
ServerSocket ss = new ServerSocket(8080)
Socket socket = ss.accept()
BufferedReader in = //获取客户端发过来的消息
new BufferedReader(
new InputStreamReader(socket.getInputStream()))
PrintWriter out = //用于向客户端发送消息
new PrintWriter(
new OutputStreamWriter(
socket.getOutputStream()),true)
while(true){
String message = in.readLine()//读取消息
if("quit".equals(message))//退出命令
break
String s[] = message.split("\\s+")
if("dir".equals(s[0])){
File dir = new File(s[1])
File[] files = dir.listFiles()
//向客户端发送文件消息
for(File file:files){
Date date = new Date(file.lastModified())
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd")//日期格式化
FileInputStream is = new FileInputStream(file)
out.println(file.getName()+"\t"+df.format(date)+"\t"+((is.available()+1023)/1024)+"k")
}
out.println("ok")
}
}
socket.close()
in.close()
out.close()
ss.close()
}
}
-------------------------------------------------------------------------------------------------------------
import java.io.*
import java.net.*
public class Client {
public static void main(String[] args) throws Exception{
InetAddress add = InetAddress.getByName(null)
Socket socket = new Socket(add,8080)
BufferedReader in = //获取服务器端发过来的消息
new BufferedReader(
new InputStreamReader(socket.getInputStream()))
PrintWriter out = //用于向服务器端发送消息
new PrintWriter(
new OutputStreamWriter(
socket.getOutputStream()),true)
out.println("dir d:/test")
String mes
while(true){
mes = in.readLine()
if("ok".equals(mes))
break
System.out.println(mes)
}
out.println("quit")
socket.close()
in.close()
out.close()
}
}
希望能帮到你。。。仍有问题可以追问或者直接HI我。。。
欢迎分享,转载请注明来源:夏雨云
评论列表(0条)