0

I am working on project and in which I make a program to create a file folder in system. When i run my program it shows:

java.io.FileNotFoundException:File 'E:\Program Files\IBM\SDP\Profin\EmailAttachment\30189\31609\T0000021811.pdf' does not exist

My code is:

    public EmailQueueAttachment[] get(Long emailQueueId)throws InvalidDAOArgumentException {
    if (emailQueueId == null) {
        throw new InvalidDAOArgumentException("Email Queue Id  can not be null.");
    }
    EmailQueueAttachmentListHelper criteria = new EmailQueueAttachmentListHelper();
    criteria.setEmailQueueId(emailQueueId);
    List<Model> emailQueueAttachmentList = getList(criteria, -1, -1).getCurrentPageData();
    if (emailQueueAttachmentList != null) {
        EmailQueueAttachment[] attachments = (EmailQueueAttachment[]) emailQueueAttachmentList.toArray(new EmailQueueAttachment[emailQueueAttachmentList.size()]);
        for(int i=0; i<attachments.length; i++){
            try {
                attachments[i].setAttachmentContent(FileUtils.readFileToByteArray(new File(SystemUtil.getEmailAttachmentFolderName() +  File.separator + emailQueueId + File.separator + attachments[i].getRecNo() + File.separator + attachments[i].getAttachmentName())));
            } catch (IOException e) {
                e.printStackTrace();
                throw new DAOException(e);
            }
        }
        return attachments;
    }
    return null;        
}

2 Answers 2

1

You need to make sure that the parent folder exists where you want to create the file

You can use File(parent).mkdirs() before trying to write your file

Sign up to request clarification or add additional context in comments.

1 Comment

Well... First I wanted to upvote... but then I read the code and found a readFileToByteArray() - no help in creating parent directories here...
0

The code you have performs a

FileUtils.readFileToByteArray(somePath);

Obviously, that File is just not there. So most likely the process that was required to write that file to that location did not work.

You have to decide what to do in these cases. Currently you fail the whole attachment-generation stuff. Maybe you'd be better of adding a default attachment in this case with some text "Attachment data not found in storage" or something.

2 Comments

well then - can you share how you solved it and upvote/accept answers accordingly?
mr. jan my read file and write file memory area were not same

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.