【发布时间】:2014-08-24 13:27:04
【问题描述】:
我想使用 jdbc 将 ImageIcon 发送到数据库。 我需要 File 对象来做到这一点。 如何将 ImageIcon 转换为 File 而不将其保存到磁盘?
File fBlob = new File(imageIcon.getImage());
FileInputStream is = new FileInputStream ( fBlob );
preparedStatement.setBinaryStream (3, is, (int) fBlob.length() );
【问题讨论】:
-
否;你需要另一种
InputStream。 -
您最初是如何创建 ImageIcon 的?我的猜测是您是从 InputStream 创建的。那么为什么不将这个 InputStream 传递给 setBinaryStream() 呢?
-
Blob blob = rset.getBlob(5);字节日期[] = blob.getBytes(1, (int)blob.length());图片.add(new ImageIcon(date));
-
另存为
Blob而不是File
标签: java swing file jdbc imageicon