www.pudn.com > FileShare.rar > FileClient.java


/* 
 * FileClient.java 
 * 
 * Created on 2008Äê4ÔÂ26ÈÕ, ÉÏÎç1:43 
 * 
 * To change this template, choose Tools | Template Manager 
 * and open the template in the editor. 
 */ 
 
/** 
 * 
 * @author 602 
 */ 
import java.io.*; 
import java.net.*; 
public class FileClient extends Thread 
{ 
     
    /** Creates a new instance of FileClient */ 
    public FileClient() { 
    } 
    public void run() 
	{ 
        try 
        { 
                File file=new File("d://","newFile.jpg"); 
		if(file.exists()) 
		{ 
			file.delete(); 
		} 
		file.createNewFile(); 
		RandomAccessFile wFile=new RandomAccessFile(file,"rw"); 
		 
		Socket server=new Socket(InetAddress.getLocalHost(),9000); 
		 
		DataInputStream in=null; 
		in=new DataInputStream(server.getInputStream()); 
		 
		byte[] buf=new byte[2048]; 
		int num=in.read(buf); 
		 
		while(num!=(-1)) 
		{ 
			wFile.write(buf); 
			num=in.read(buf); 
		} 
		in.close(); 
		wFile.close(); 
        } 
        catch(Exception e) 
        {} 
		 
	} 
     
}