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

24
LINES

< > BotCompany Repo | #1009008 // loadTextFileWithEncoding

JavaX fragment (include)

public static String loadTextFileWithEncoding(String fileName, S encoding) {
  return loadTextFileWithEncoding(fileName, null, encoding);
}

public static String loadTextFileWithEncoding(String fileName, String defaultContents, S encoding) {
  try {
    if (!new File(fileName).exists())
      return defaultContents;

    FileInputStream fileInputStream = new FileInputStream(fileName);
    InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, encoding);
    return loadTextFile(inputStreamReader);
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}

  public static String loadTextFileWithEncoding(File f, String defaultContents, S encoding) {
    ret f == null ? defaultContents : loadTextFileWithEncoding(f.getPath(), defaultContents, encoding);
  }
  
public static String loadTextFileWithEncoding(File fileName, S encoding) {
  return loadTextFileWithEncoding(fileName, null, encoding);
}

Author comment

Began life as a copy of #1001049

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1009008
Snippet name: loadTextFileWithEncoding
Eternal ID of this version: #1009008/4
Text MD5: 0a0546ec78190157557892b34dced123
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-06-26 17:50:43
Source code size: 961 bytes / 24 lines
Pitched / IR pitched: No / No
Views / Downloads: 390 / 407
Version history: 3 change(s)
Referenced in: [show references]