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

23
LINES

< > BotCompany Repo | #1000744 - loadBinaryFile (function)

JavaX fragment (include)

1  
public static byte[] loadBinaryFile(String fileName) {
2  
 try {
3  
  if (!new File(fileName).exists())
4  
    return null;
5  
6  
  FileInputStream in = new FileInputStream(fileName);
7  
8  
  byte buf[] = new byte[1024];
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) {
22  
  return loadBinaryFile(file.getPath());
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 (function)
Eternal ID of this version: #1000744/1
Text MD5: 8d872325da80d84977b5db4d915bc4d8
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-08-24 12:54:46
Source code size: 582 bytes / 23 lines
Pitched / IR pitched: No / No
Views / Downloads: 444 / 4385
Referenced in: [show references]

Formerly at http://tinybrain.de/1000744 & http://1000744.tinybrain.de