我有一个使用这个字符串和字节数组的接口
public interface EmailAttachment {
String getFileName();
String getFileVersion();
byte[] getContent();
String getType();
}我想把所有这些都放在一个文件中,在我的类Service中,我如何调用?:
@Override
public Boolean sendEmail(EmailAttachment attachment) {
File file = new File( "HERE,I want to bring everything");
uploadFile(file);
}如果我使用attachment.getFileName(),attachment.getFileVersion(),attachment.getContent(),attachment.getType(),它会带来一个错误,因为文件需要一个路径
发布于 2020-02-01 01:48:40
尝试一下,使用文件名创建一个文件对象,并将其传递给FileOutputStream。
OutputStream接受字节数组将其存储在文件中,上传完成后关闭流。
String FILENAME = "";
File file = new File(FILENAME);
OutputStream os = new FileOutputStream(file);
// here you can write bytes to file using FileOutputStream
os.write(bytes);
// Close the file
os.close(); https://stackoverflow.com/questions/60008658
复制相似问题