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).

1  
public static byte[] loadBinaryFile(String fileName, int bufSize default defaultBufferedOutputStreamSize()) {
2  
 try {
3  
  if (!new File(fileName).exists())
4  
    return null;
5  
6  
  FileInputStream in = new FileInputStream(fileName);
7  
8  
  byte buf[] = new byte[bufSize];
9  
  ByteArrayOutputStream out = new ByteArrayOutputStream();
10  
  int l;
11  
  while (true) {
12  
    l = in.read(buf);
13  
    if (l <= 0) break;
14  
    out.write(buf, 0, l);
15  
  }
16  
  in.close();
17  
  return out.toByteArray();
18  
 } catch (IOException e) { throw new RuntimeException(e); }
19  
}
20  
21  
public static byte[] loadBinaryFile(File file, int bufSize default defaultBufferedOutputStreamSize()) {
22  
  return loadBinaryFile(file.getPath(), bufSize);
23  
}

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: 754 / 4802
Version history: 5 change(s)
Referenced in: [show references]