Java 在Junit中使用getBytes设置附件

Java 在Junit中使用getBytes设置附件,java,junit,Java,Junit,下面是我用于junit保存附件的代码。它保存在DB中,但当我浏览应用程序时,收到一条错误消息,如“无法打开'test109.pdf',因为它不是受支持的文件类型,或者文件可能已损坏”。其他文件类型也是如此。在这里使用.getBytes有什么问题吗 @Test public void saveAttachment() throws SerException { final File blobIn = new File("F:\\src\\test4.pdf"); InputStream

下面是我用于junit保存附件的代码。它保存在DB中,但当我浏览应用程序时,收到一条错误消息,如“无法打开'test109.pdf',因为它不是受支持的文件类型,或者文件可能已损坏”。其他文件类型也是如此。在这里使用.getBytes有什么问题吗

@Test 
public void saveAttachment() throws SerException
{

final File blobIn = new File("F:\\src\\test4.pdf");
    InputStream blobIs = null;
    try {
        blobIs = new FileInputStream(blobIn);   
AttachmentReqDocument attachmentReqDocument = AttachmentReqDocument.Factory.newInstance();
    AttachmentReq attachmentReq = attachmentReqDocument.addNewSaveAttachmentReq();
    attachmentReq.setSuId("105"); 
    attachmentReq.setTId("104532520"); 
    attachmentReq.setFileName("test109.pdf"); 
    attachmentReq.setAttachment("test112".getBytes()); 
    attachmentReq.setUserId("test004"); 
    attachmentReqDocument.getSaveAttachmentReq().setInUserId(null);
    AttachmentResDocument attachmentResDocument =       
            testManager.saveTestAttachment(attachmentReqDocument);
    System.out.println(attachmentResDocument);
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        System.out.println("File not found");
    }catch (IOException e) {
        // TODO Auto-generated catch block
        System.out.println("Error Reading the bytes");
    }
}
非常感谢您的任何帮助:)

提前谢谢

我认为您希望附加
blobIs
inputStream中的字节,而不是
“test112”.getBytes()
,后者显然不是有效的pdf编码数据。

错误是,“test112”不构成有效的pdf文档。这不是预期的吗?
blobIn
blobIs
在您的代码中有什么用途?