日期:2014-05-20  浏览次数:20834 次

数据库blob类型文件写入本地影片问题
Connection   con   =   null;
PreparedStatement   pstmt   =   null;
ResultSet   rst   =   null;
int   i   =   0;
String   sql   =   "select   *   from   person ";
InputStream   is   =   null;
OutputStream   os   =   null;
try   {

long   beginTime   =   System.currentTimeMillis();
Class.forName( "oracle.jdbc.driver.OracleDriver ");
con   =   DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:aolei ",   "aolei ",   "aolei ");
pstmt   =   con.prepareStatement(sql);
rst   =   pstmt.executeQuery();
while   (rst.next())   {
BLOB   blob   =   (BLOB)   rst.getBlob(4);
is   =   blob.getBinaryStream();
File   file   =   new   File( "d:/out/output "+i+ ".txt ");

try   {
os   =   new   FileOutputStream(file);
}   catch   (FileNotFoundException   e2)   {
//   TODO   Auto-generated   catch   block
e2.printStackTrace();
}
byte[]   b   =   new   byte[1024];
int   len   =   0;
try   {
while   ((len   =   is.read(b))   !=   -1)   {
os.write(b,   0,   len);
}
}   catch   (IOException   e)   {
//   TODO   Auto-generated   catch   block
e.printStackTrace();
}

try   {
os.flush();
is.close();
}   catch   (Exception   e)   {
//   TODO:   handle   exception
}

i++;
}
//   System.out.println( "length "+a);
System.out.println( "记录数 "   +   i   +   "个 ");
long   endTime   =   System.currentTimeMillis();
float   sumTime   =   (float)   (endTime   -   beginTime)   /   1000;
System.out.println(sumTime   +   "秒 ");
}   catch   (ClassNotFoundException   e)   {
e.printStackTrace();
System.out.println( "没找到驱动类 ");
}   catch   (SQLException   e)   {
e.printStackTrace();
}   finally   {
try   {
if   (rst   !=   null)   {
rst.close();
}
if   (pstmt   !=   null)   {
pstmt.close();
}
if   (con   !=   null)   {
con.close();
}
if   (is   !=   null)   {
is.close();
}
if   (os   !=   null)   {
os.close();
}
}   catch   (SQLException   s)   {
s.printStackTrace();
}
}


请问byte[]   b   =   new   byte[1024];
int   len   =   0;
try   {
while   ((len   =   is.read(b))   !=   -1)   {
os.write(b,   0,   len);
}
}
          b的范围,是越大存入影片速度越快吗


------解决方案--------------------
探讨
哦,谢谢,那最大范围是多大呢?