Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

23
LINES

< > BotCompany Repo | #1000744 // loadBinaryFile

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (63L/1K).

public static byte[] loadBinaryFile(String fileName, int bufSize default defaultBufferedOutputStreamSize()) {
 try {
  if (!new File(fileName).exists())
    return null;

  FileInputStream in = new FileInputStream(fileName);

  byte buf[] = new byte[bufSize];
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  int l;
  while (true) {
    l = in.read(buf);
    if (l <= 0) break;
    out.write(buf, 0, l);
  }
  in.close();
  return out.toByteArray();
 } catch (IOException e) { throw new RuntimeException(e); }
}

public static byte[] loadBinaryFile(File file, int bufSize default defaultBufferedOutputStreamSize()) {
  return loadBinaryFile(file.getPath(), bufSize);
}

Author comment

Began life as a copy of #2000553

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1000744
Snippet name: loadBinaryFile
Eternal ID of this version: #1000744/6
Text MD5: 1ad63989f76c87aa5b770f02b1603089
Transpilation MD5: 8f7c978937ff23b7d7ee966fbb67053f
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-11-08 14:46:07
Source code size: 704 bytes / 23 lines
Pitched / IR pitched: No / No
Views / Downloads: 618 / 4643
Version history: 5 change(s)
Referenced in: #1002427 - Accellerating 629 (SPIKE)
#1006654 - Standard functions list 2 (LIVE, continuation of #761)
#3000382 - Answer for ferdie (>> t = 1, f = 0)
#3000383 - Answer for funkoverflow (>> t=1, f=0 okay)