Java活用生活

ログイン

オンライン状況

オンラインユーザー1人
ログインユーザー0人
登録ユーザー2人

カウンタ

COUNTER335464

日誌

MyDoc(備忘録) >> 記事詳細
2022/12/18

読みこんだファイルの文字列をbyte配列データで返す

固定リンク | by:aramaki
 読みこんだファイルの文字列をbyte配列データで返す
--------------------------------------------------------------------------------
private static byte[] readFileToByte2(String filePath) throws Exception {
FileInputStream fileInputStream = new FileInputStream(filePath);
BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream);
ByteArrayOutputStream out = new ByteArrayOutputStream();

int s;
// 1バイトずつ読み込む
while ((s = bufferedInputStream.read()) != -1) {
// 読み込んだデータをバイト配列に格納する
out.write(s);
}

byte[] tmp=out.toByteArray();

fileInputStream.close();
out.close();
return tmp;
}
18:37 | 投票する | 投票数(0) | コメント(0)
Copyright © Java活用生活 All Rights Reserved .