简体   繁体   English

如何直接从内容创建 java.io.File 实例而不在磁盘上创建临时文件?

[英]How to create a java.io.File instance diectly from content without creating a temporary file on disk ?

I have a library that sends an attachment along with an email after accepting a java.io.File instance as attachment.我有一个库,在接受 java.io.File 实例作为附件后,它会随电子邮件一起发送附件。 Now I have html content with me to send as an attachment.现在我有 html 内容可以作为附件发送。

Is it possible to create a File instance to pass to this Java API when I have the content instead of creating a temporary physical file on disk ?当我拥有内容而不是在磁盘上创建临时物理文件时,是否可以创建一个 File 实例来传递给这个 Java API?

A File is just a filename.文件只是一个文件名。 There is nothing on the disk when you instantiate one unless there really is such a file, or you do some I/O, or you call createNewFile() and friends.当你实例化一个磁盘时,磁盘上什么也没有,除非真的有这样的文件,或者你做了一些 I/O,或者你调用createNewFile()和朋友。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM