blob-file
 public static void dbToFile(Connection conn, String sql, String fileName) throws
        SQLException, IOException
    {
        InputStream in = null;
        OutputStream out = null;
        //conn.setAutoCommit(false);        Statement stmt = conn.createStatement();
        ResultSet rs = stmt.executeQuery(sql);        if (rs.next())
        {
            Blob blob = rs.getBlob(1);
            // Get the input stream which will be used to read
            // data from the table.            in = ( (oracle.sql.BLOB) blob).getBinaryStream();            int bufferSize = (int) ( (oracle.sql.BLOB) blob).getBufferSize();            // Create a buffered stream to write to the file
            out = new BufferedOutputStream(new FileOutputStream(fileName),
                                           bufferSize);            // Create a byte buffer and start reading from the file
            byte[] b = new byte[bufferSize];
            int count = in.read(b, 0, bufferSize);            // write the bytes using the OutputStream
            // loop until all bytes are written to the table
            System.out.print("count=" + count);
            while (count != -1)
            {
                System.out.print(".");
                out.write(b, 0, count);
                count = in.read(b, 0, (int) bufferSize);
            }
            System.out.println("Complete");
            out.close();
            out = null;
            in.close();
            in = null;            conn.commit();
            //conn.setAutoCommit(true);
            resultSets.add(rs);
            stmts.add(stmt);
        }
    }
文件删除:
 public void delFile(String fileName)
    {
        File f = new File(fileName);
        String fileAbsName = "";        if (f.isFile())
        {
            f.delete();
        }
        else if (f.isDirectory())
        {
            String fName[] = f.list();            for (int i = 0; i < fName.length; i++)
            {
                fileAbsName = fileName + "/" + fName[i];
                System.out.println("fName=" + fName[i]);                File fChild = new File(fileAbsName);
                if (fChild.isFile())
                {
                    fChild.delete();
                }
                else
                {
                    delFile(fileAbsName);
                    if (fChild.list().length == 0)
                    {
                        fChild.delete();
                    }                }            }        }
    }

解决方案 »

  1.   

    blob里放的是流,然后save程binary文件,再从binary文件里读出一个流,还是原先blob里的那个流,这样有意义吗?blob那到一个流,直接播放不就是了,还免了后续删除文件那档子事。
      

  2.   

    楼上的大哥什么意思啊?
    我现在也有一个算法可以将BLOB字段中的内容导出成文件,但速度实在是太慢了,倒出一个2.63M的文件要花上两三分钟!!!!
    我受不料,所以上来请教各位大哥有没有比较快的导出成文件的方法,速度慢的话用户不乐意啊,非常着急,谢谢各位了