【 解 説 】
Webサービスでバイナリをアップするときなどは、byte[]で渡します。
【 例 文 】
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
public byte[] createBin() { InputStream in = null; byte[] pix = null; try { in = new FileInputStream("before.bin"); // <-バイナリファイル ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] b = new byte[1024]; int j; while ((j = in.read(b)) != -1) { baos.write(b, 0, j); } pix = baos.toByteArray(); } catch (IOException e) { e.printStackTrace(); } finally { if (in != null) { try { in.close(); } catch (IOException e) { e.printStackTrace(); } } } return pix; } |
■お薦め参考関連資料
Sun、Sun Microsystems、サンのロゴマーク、Java、Solarisに関連するすべての商標およびロゴマークは、米国 Sun Microsystems, Inc. の米国およびその他の国における商標または登録商標です。