java二進制讀取
Ⅰ java 以二進制流的方式讀取mysql 中的blob文件,並寫入本地文件夾下
//配置資料庫連接驅動
String sql = xxxxxxxx;//要查詢的sql
PreparedStatement ps = conn.prepareStatement(sql);
String path = xxxxxxx;
ResultSet rs = ps.executeQuery();
while (rs.next()) {
InputStream is = rs.getBlob(x).getBinaryStream();//x為要取的BLOB位置
FileOutputStream os = new FileOutputStream(path + "//"
+ "存放的文件名"+「.zip」);
byte[] buff = new byte[1024];
while ((is.read(buff)) != -1) {
os.write(buff);
}
os.close();
is.close();
}
ps.close();
conn.close();
Ⅱ java怎麼實現讀取一個文件,拿到二進制流
InputStream 就是讀取二進制文件的, 任何文件都可以用這個流來讀, 也叫位元組輸入流
Ⅲ Java 讀取二進制文件 ,讀八個位元組,然後轉換成一個double,怎麼寫 我知道怎麼讀四個位元組轉成int的。
先申明一下你的前提是二進制文件,讀取8個位元組,那培埋么可以這么做:
public double readDouble(InputStream in) throws IOException {
byte[] tmp = new byte[8 * 8];//8個位元組蔽中歲長度宏睜
if (in != null && (in.read(tmp) != -1)) {
String str = new String(tmp);
return Double.valueOf(str);
}
return -1;
}