ImageName是一个图片文件, 文件操作代码如下:
ObjFile = new java.io.File(ImageName);
char[] Chr = new char[10];
out.clear();
try {
if (ObjFile.exists()) { //文件存在
ObjFileReader = new java.io.FileReader(ObjFile); //创建读文件对象
while ((intLength = ObjFileReader.read(ChrBuffer)) != -1) { //读文件内容
out.write(ChrBuffer, 0, intLength);
}
ObjFileReader.close(); //关闭读文件对象
}
else {
out.println("File Not Found" + ImageName); //文件不存在
}
}
catch (Exception e) {
System.out.println(e.toString());
}如果ImageName是从oralce中blob取数据, 上述程序如何修改?
我改写后, 代码如下:Connection con=null;
PreparedStatement sql=null; //从数据库取图章
ResultSet rs =null;
ByteBuffer = new byte[10240];
out.clear();
try {
con=oraconndb.getConnection(); //建立数据库链接, JavaBean略
sql=con.prepareStatement(ImageName);//执行数据库操作,取数据
rs = sql.executeQuery();
if (rs.next()) { //文件存在
ObjInputStream = rs.getBinaryStream("images"); //取出blob
while ((intLength = ObjInputStream.read(ByteBuffer)) >0) { //读内容
out.write(ByteBuffer, 0, intLength);
}
ObjInputStream.close(); //关闭对象
}
else {
out.println("Not Found Record"); //不存在
}
}
catch (Exception e) {
System.out.println(e.toString());
}
报错如下:
The method write(int) in the type Writer is not applicable for the arguments (by
te[], int, int)请问是什么原因
ObjFile = new java.io.File(ImageName);
char[] Chr = new char[10];
out.clear();
try {
if (ObjFile.exists()) { //文件存在
ObjFileReader = new java.io.FileReader(ObjFile); //创建读文件对象
while ((intLength = ObjFileReader.read(ChrBuffer)) != -1) { //读文件内容
out.write(ChrBuffer, 0, intLength);
}
ObjFileReader.close(); //关闭读文件对象
}
else {
out.println("File Not Found" + ImageName); //文件不存在
}
}
catch (Exception e) {
System.out.println(e.toString());
}如果ImageName是从oralce中blob取数据, 上述程序如何修改?
我改写后, 代码如下:Connection con=null;
PreparedStatement sql=null; //从数据库取图章
ResultSet rs =null;
ByteBuffer = new byte[10240];
out.clear();
try {
con=oraconndb.getConnection(); //建立数据库链接, JavaBean略
sql=con.prepareStatement(ImageName);//执行数据库操作,取数据
rs = sql.executeQuery();
if (rs.next()) { //文件存在
ObjInputStream = rs.getBinaryStream("images"); //取出blob
while ((intLength = ObjInputStream.read(ByteBuffer)) >0) { //读内容
out.write(ByteBuffer, 0, intLength);
}
ObjInputStream.close(); //关闭对象
}
else {
out.println("Not Found Record"); //不存在
}
}
catch (Exception e) {
System.out.println(e.toString());
}
报错如下:
The method write(int) in the type Writer is not applicable for the arguments (by
te[], int, int)请问是什么原因
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货