org.javalite.common.Util.readFile()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(1.9k)|赞(0)|评价(0)|浏览(229)

本文整理了Java中org.javalite.common.Util.readFile()方法的一些代码示例,展示了Util.readFile()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util.readFile()方法的具体详情如下:
包路径:org.javalite.common.Util
类名称:Util
方法名:readFile

Util.readFile介绍

[英]Reads contents of file fully and returns as string.
[中]完全读取文件内容并以字符串形式返回。

代码示例

代码示例来源:origin: javalite/activejdbc

  1. /**
  2. * Reads contents of file fully and returns as string.
  3. *
  4. * @param fileName file name.
  5. * @return contents of entire file.
  6. */
  7. public static String readFile(String fileName) {
  8. return readFile(fileName, "UTF-8");
  9. }

代码示例来源:origin: com.github.tchoulihan/javalite-common

  1. /**
  2. * Reads contents of file fully and returns as string.
  3. *
  4. * @param fileName file name.
  5. * @return contents of entire file.
  6. */
  7. public static String readFile(String fileName) {
  8. return readFile(fileName, "UTF-8");
  9. }

代码示例来源:origin: org.javalite/javalite-common

  1. /**
  2. * Reads contents of file fully and returns as string.
  3. *
  4. * @param fileName file name.
  5. * @return contents of entire file.
  6. */
  7. public static String readFile(String fileName) {
  8. return readFile(fileName, "UTF-8");
  9. }

代码示例来源:origin: org.javalite/javalite-templator

  1. private String loadTemplate(String templateName){
  2. String slash = templateName.startsWith("/") ? "" : "/";
  3. //for tests, load from location
  4. if (templateLocation != null) {
  5. return readFile(templateLocation + slash + templateName, "UTF-8");
  6. }
  7. //proceed to load from servlet context
  8. String fullPath = "/WEB-INF/views" + slash + templateName;
  9. // First try to open as plain file (to bypass servlet container resource caches).
  10. String realPath = servletContext.getRealPath(fullPath);
  11. try {
  12. if (realPath != null) {
  13. File file = new File(realPath);
  14. if (!file.isFile()) {
  15. throw new TemplateException(realPath + " is not a file");
  16. }
  17. if (file.canRead()) {
  18. return readFile(realPath, "UTF-8");
  19. }
  20. }
  21. } catch (SecurityException ignore) {}
  22. try {
  23. URL url = servletContext.getResource(fullPath);
  24. return Util.read(url.openStream(), "UTF-8");
  25. } catch (Exception e) {throw new TemplateException(e);}
  26. }

相关文章