0
FTP 및 클라이언트를 작성하여 텍스트 파일을 만든 다음 보내면 정상적으로 작동합니다. 하지만 다른 형식의 파일을 보내 자마자 클라이언트 측에서받은 파일이 손상된 것입니다. 여기에서, 파일특정 파일 형식이 FTP를 통해 손상된 경우
try
{
fis=new FileInputStream(filenm);
}
catch(FileNotFoundException exc)
{
filexists=false;
System.out.println("FileNotFoundException:"+exc.getMessage());
}
if(filexists)
{
System.out.println("sent");
sendBytes(fis, output);
fis.close();
}
private static void sendBytes(FileInputStream f,OutputStream op)throws Exception
{
byte[] buffer=new byte[1024];
int bytes=0;
while((bytes=f.read(buffer))!=-1)
{
op.write(buffer,0,bytes);
}
}
FIS 송신 해요 코드 - FileInputStream의 객체 출력 - OutputStream에 객체 (Socket.getOutputStream는())
클라이언트 코드 :File f=new File(dir,"file2");
FileOutputStream fos=new FileOutputStream(f);
DataOutputStream dops=new DataOutputStream(fos);
System.out.println("2nd Stage");
while(done)
{
fc2=br.read();
if(fc2==-1)
{
done=false;
}
else
{
dops.write(fc2);
}
}
fos.close();
System.out.println("File Recieved");
올바른 흐름을 사용하고 있습니까?
전송 모드를 IMAGE로 설정했는지 기억 했습니까? –
왜 서버와 클라이언트에서 서로 다른 읽기 루프를 사용합니까? 서버 코드가 훨씬 좋습니다. – EJP
@raymond이 소리가 어리석은 경우 미안하지만 전송 모드를 이미지로 설정하는 방법은 이미지 파일보다 많은 파일 형식을 전송하는 것입니다. –