Libraryless. Click here for Pure Java version (2523L/16K).
static S loadTextFile(S fileName) { return loadTextFile(fileName, null); } static S loadTextFile(File f, S defaultContents, S encoding default "UTF-8") ctex { ifndef LeanMode checkFileNotTooBigToRead(f); endifndef if (f == null || !f.exists()) ret defaultContents; FileInputStream fileInputStream = new FileInputStream(f); InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, encoding); ret loadTextFile(inputStreamReader); } public static String loadTextFile(File fileName) { return loadTextFile(fileName, null); } static S loadTextFile(S fileName, String defaultContents) { ret fileName == null ? defaultContents : loadTextFile(newFile(fileName), defaultContents); } static S loadTextFile(Reader reader) throws IOException { new StringBuilder builder; try { char[] buffer = new char[1024]; int n; while (-1 != (n = reader.read(buffer))) builder.append(buffer, 0, n); } finally { reader.close(); } ret str(builder); }
Began life as a copy of #2000322
download show line numbers debug dex old transpilations
Travelled to 18 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mowyntqkapby, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, whxojlpjdney, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1001049 |
Snippet name: | loadTextFile (function) |
Eternal ID of this version: | #1001049/10 |
Text MD5: | fc8b2f7fdca4a671ce9dfc4e2d3a238c |
Transpilation MD5: | 9c115e8428deb9ac2122d9822b2aca91 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-07-27 17:33:11 |
Source code size: | 1033 bytes / 35 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 984 / 9496 |
Version history: | 9 change(s) |
Referenced in: | [show references] |