public class filesend {
public static void main(String[] args) throws Exception {
ServerSocket ss = new ServerSocket(7777);
Socket s = ss.accept();
DataOutputStream dos = new DataOutputStream(s.getOutputStream());
FileInputStream fis = new FileInputStream(
"D:/소오름.png");
byte[] buffer=new byte[8*1024];
System.out.println("전송시작");
while(true){
int len=fis.read(buffer, 0, 8*1024);
if(len==-1){
System.out.println("파일 전송 완료");
break;
}
dos.write(buffer, 0, len);
dos.flush();
}
}
}
import java.io.DataInputStream;
import java.io.FileOutputStream;
import java.net.Socket;
public class FileR {
public static void main(String[] args)throws Exception {
Socket s=new Socket("192.168.1.241",7777);
DataInputStream dis=new DataInputStream(s.getInputStream()); //데이터 읽어오기
FileOutputStream fos=new FileOutputStream("new.png"); //전송된 파일서 파일에 받아쓰기
byte[] buffer=new byte[8*1024];
while(true){
int len=dis.read(buffer, 0, 8*1024);
if(len==-1){
break;
}
fos.write(buffer, 0, len);
}
}
}
'개발하자 > JAVA고급' 카테고리의 다른 글
웹사이트소스불러오기 (0) | 2015.02.18 |
---|---|
java.util.regex.PatternSyntaxException (0) | 2015.02.10 |
퇴장기능추가 (0) | 2015.02.06 |
awt 채팅 Server&Guest (0) | 2015.02.06 |
awt 채팅 Client (0) | 2015.02.06 |