javaÀûÓÃSocketÍøÂç´«µÝÎļþ
·þÎñÆ÷¶Ë:
package com.huahua;
import java.io.BufferedOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
public class ServerThread extends Thread {
private Socket socket;
public ServerThread(Socket socket) {
super();
this.socket = socket;
}
public void run(){
try {
while(true){
DataInputStream in = new DataInputStream(socket.getInputStream());
//½ÓÊÕ±£´æµÄ·¾¶
String path = "e:\\" + in.readUTF();
//½ÓÊÕµÄÎļþ³¤¶È
long length = in.readLong();
//±£´æÎļþ
DataOutputStream out = new DataOutputStream(new BufferedOutputStream(
new FileOutputStream(path)));
byte[] buf = new byte[1024];
int len = 0;
while((len=in.read(buf))!=-1){
out.write(buf,0,buf.length);
}
out.flush();
out.close();
in.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args){
try {
ServerSocket serverSocket = new ServerSocket(9999);
while(true){
new ServerThread(serverSocket.accept()).start();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
¿Í»§¶Ë:
package com.huahua;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.Socket;
public class Client{
public static void main(String[] args){
FileInputStream fin = null;
DataOutputStream out = null;
try {
Socket socket = new Socket("127.0.0.1",9999);
File file = new File("f:\\ÕÅ»ÝÃà - ²Êºç.wma");
out = new DataOutputStream(socket.getOutputStream());
//´«ËÍÎļþÃû³Æ
out.writeUTF(file.getName());
out.flush();
//´«ËÍÎļþ³¤¶È
out.writeLong(file.length());
out.flush();
//´«ËÍÎļþ
fin = new FileIn
Ïà¹ØÎĵµ£º
=====suppose such a method:
public static void openFile(String fileName, PrintWriter stream) throws FileNotFoundException
{
stream = new PrintWriter(fileName);
}
=====then we want to use it this way:
PrintWriter toFile = null;
try
{
openFile("data.txt", t ......
import javax.servlet.*;
¡¡¡¡import javax.servlet.http.HttpServletResponse;
¡¡¡¡import java.io.IOException;
¡¡¡¡/**
¡¡¡¡* ÓÃÓÚµÄʹ Browser ²»»º´æÒ³ÃæµÄ¹ýÂËÆ÷
¡¡¡¡*/
¡¡¡¡public class ForceNoCacheFilter
¡¡¡¡implements Filter
¡¡¡¡{
¡¡¡¡publi ......
1. ʼÖÕʹÓà MVC ¿ò¼Ü¡£
½«ÒµÎñÂß¼£¨Java Bean ºÍ EJB ×é¼þ£©´Ó¿ØÖÆÆ÷Âß¼£¨Servlet/Struts ²Ù×÷£©ºÍ±íʾÂß¼£¨JSP¡¢XML/XSLT£©ÖÐÇåÎúµØ·ÖÀë³öÀ´¡£Á¼ºÃµÄ·Ö²ã¿ÉÒÔ´øÀ´Ðí¶àºÃ´¦¡£
×¢:¶ÔÓÚһЩСÐ͵ĻòÕßÒµÎñÏà¶Ô¼òµ¥µÄϵͳ¶øÑÔ,Óÿò¼Ü¿ª·¢²¢²»ÄÜ´øÀ´ÈκÎÐ§Òæ,²¢ÇÒÎÒÉîÐÅÔÚһЩÏîÄ¿¿ª·¢ÖÐ,ÌØ±ðÊǽö½öÓÉij¸öÈ˶ÀÁ ......
ÐèÒª×öÒ»¸ö×ÀÃæµÄС¶«Î÷£¬ÓÉÓÚÖÁ½ñΪֹֻ»áдJava£¬ËùÒÔÖ»ÓÐÓÃswingÀ´×öÁË¡£ÅóÓÑ˵Delphi×öÆðÀ´ºÜ¿ì£¬µ«ÎÒûʱ¼äȥѧÁË£¬Ò»¶¨Òª¿ªÊ¼ºáÏò·¢Õ¹ÁË¡£
ÔÀ´¶ÌÔݵÄ×ö¹ýNetBeansµÄrcp¿ª·¢£¬µ«ËüµÄ´úÂë×éÖ¯Óеã¹ýÓÚ¸´ÔÓ£¬²»¹ýÎÒÒª×öµÄ²»ÊǺܴóµÄ¶«Î÷£¬µ«»¹ÊÇÏëÏÈÕÒEclips ......