作者在 2011-04-08 14:27:40 发布以下内容
/**
* 将文件写入到有磁盘中。。
* @param name 图片名称
* @param file 将图片写入的路径
*/
public void readImage(String name,File file){
String sql = null;
FileOutputStream sout = null;
InputStream in = null;
PreparedStatement ps = null;
ResultSet rs = null;
Connection jdbcCon = new JDBCFactory().getConnection();
sql="select content from uploadfile where name='"+name+"'";
try {
ps = jdbcCon.prepareStatement(sql);
rs = ps.executeQuery();
if (rs.next()) {
//文件输出流
in = rs.getBinaryStream(1);
sout = new FileOutputStream(file);
byte b[] = new byte[0x7a120];
while (in.read(b) != -1) {
sout.write(b);
//将缓冲区的输入输出到页面
in.read(b);
}
sout.flush();
sout.close();
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
* 将文件写入到有磁盘中。。
* @param name 图片名称
* @param file 将图片写入的路径
*/
public void readImage(String name,File file){
String sql = null;
FileOutputStream sout = null;
InputStream in = null;
PreparedStatement ps = null;
ResultSet rs = null;
Connection jdbcCon = new JDBCFactory().getConnection();
sql="select content from uploadfile where name='"+name+"'";
try {
ps = jdbcCon.prepareStatement(sql);
rs = ps.executeQuery();
if (rs.next()) {
//文件输出流
in = rs.getBinaryStream(1);
sout = new FileOutputStream(file);
byte b[] = new byte[0x7a120];
while (in.read(b) != -1) {
sout.write(b);
//将缓冲区的输入输出到页面
in.read(b);
}
sout.flush();
sout.close();
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}