import javax.activation.DataHandler; import javax.activation.FileDataSource; import java.io.FileOutputStream; import java.io.File; public class AttachmentTest { FileOutputStream fos; public void test(int a){ System.out.println(a + "test!!!"); } public void test2(DataHandler dhSource){ System.out.println("test2!"); } public void setFile(DataHandler dh){ if(dh == null) System.out.println("attachment is null"); else System.out.println("Server got File"); try{ fos = new FileOutputStream("FromClientFile.gif"); dh.writeTo(fos); fos.flush(); } catch( java.io.FileNotFoundException e) { e.printStackTrace(); } catch( java.io.IOException e) { e.printStackTrace(); } } }