當前位置:首頁 » 編程語言 » java二進制讀取

java二進制讀取

發布時間: 2025-07-03 11:55:52

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;
}

熱點內容
java返回this 發布:2025-10-20 08:28:16 瀏覽:593
製作腳本網站 發布:2025-10-20 08:17:34 瀏覽:888
python中的init方法 發布:2025-10-20 08:17:33 瀏覽:581
圖案密碼什麼意思 發布:2025-10-20 08:16:56 瀏覽:765
怎麼清理微信視頻緩存 發布:2025-10-20 08:12:37 瀏覽:684
c語言編譯器怎麼看執行過程 發布:2025-10-20 08:00:32 瀏覽:1012
郵箱如何填寫發信伺服器 發布:2025-10-20 07:45:27 瀏覽:255
shell腳本入門案例 發布:2025-10-20 07:44:45 瀏覽:113
怎麼上傳照片瀏覽上傳 發布:2025-10-20 07:44:03 瀏覽:806
python股票數據獲取 發布:2025-10-20 07:39:44 瀏覽:712