제가 PC(서버{JAVA}) <ㅡ> 안드로이드 폰(클라이언트) 간에 소켓통신을 이용애서 이미지를 전송하려고 하고 있는데... 이미지를 전송하는 것 까지 했습니다. 그런데.. 문제는 이지를 폰에서 받아서 저장을 하는데... 저장된 파일이 깨져요... 그림이 아예 파란색으로 되어 열면 그림이 안보이거나 윙 아주 조금만 나오고 나머지는 이상하게 깨져서 나오거나 하네요.... 왜 그런건지 좀 알려주세여...ㅜㅜ
밑에 소스 있는데... 어디가 잘못됬는지.. 아니면 뭘더 추가하거나... 바꿔야 할지 좀 알려주세요...ㅠㅠ
그리고 이미지는 밑에처럼 이렇게 깨져서 나옵니다..
### 원본 ### ### 전송된 이미지 ###

################################## 서버 소스 (자바) ############################################
public void run() {
// TODO Auto-generated method stub
System.out.println("대기중.......");
try {
server = new ServerSocket(Port);
System.out.println("수신중.......");
client = server.accept();
OutputStream output = client.getOutputStream();
System.out.println("client 접속......");
try
{
FileInputStream in = new FileInputStream(new File("C:\\Users\\seongu\\Documents\\serverUI.jpg"));
System.out.println("이미지 추출.........");
byte[] buf = new byte[1024];
System.out.println("이미지 전송 중.........");
while(in.read(buf)>0)
{
i++;
output.write(buf);
output.flush();
}
System.out.println("숫자 >>>>>> "+i);
System.out.println("이미지 전송완료........");
output.close();
}catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
client.close();
server.close();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
################################## 클라이언트 소스 (안드로이드) #############################################
class send{
private Socket socket;
private String ip = "192.168.0.25"; // IP
private int port = 9999; // PORT번호
private int i=0;
public void run()
{
try
{
Log.d("Socket>>>>>>", "ip and port open....");
socket = new Socket(ip,port);
Log.d("Socket>>>>>>", "ip and port open Success!!!!!");
/*BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
String str = in.readLine();
Log.d("Socket>>>>>>", "data name :"+str);*/
try
{
File f = new File("/mnt/sdcard/","test67"+".jpg");
Log.d("Socket>>>>>>", "file craeted Success!!!!!!");
FileOutputStream output = new FileOutputStream(f);
byte[] buf = new byte[1024];
Log.d("Socket>>>>>>", "file loading......");
while(socket.getInputStream().read(buf)>0)
{
i++;
output.write(buf);
output.flush();
}
Log.d("Socket>>>>>>", "number>>>>>> "+i);
Log.d("Socket>>>>>>", "file doen commplede");
output.close();
Log.d("Socket>>>>>>", "test67"+".jpg "+"down Success :");
}
catch(IOException e)
{
e.printStackTrace();
}
finally
{
socket.close();
}
}
catch(IOException e)
{
e.printStackTrace();
}
}




읽어 들여서 파일에 쓸때...
byte수를 정해줘야 하지 않을까요?
0부터 몇번째 byte까지...
마지막에 나머지가 남는다면 몇바이트 write하게 될지 생각해보세요...