SHARE
TWEET

FileUtil.java

Giuseppe499 Oct 27th, 2015 113 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.main;
  2.  
  3.  
  4. import java.io.BufferedReader;
  5. import java.io.InputStreamReader;
  6.  
  7. public class FileUtil
  8. {
  9.         public static String readFromFile(String name)
  10.         {
  11.             StringBuilder source = new StringBuilder();
  12.             try
  13.             {
  14.                 BufferedReader reader = new BufferedReader(
  15.                                             new InputStreamReader(
  16.                                                 ShaderProgram.class
  17.                                                              .getClassLoader()
  18.                                                              .getResourceAsStream(name)));
  19.  
  20.                 String line;
  21.                 while ((line = reader.readLine()) != null)
  22.                 {
  23.                     source.append(line).append("\n");
  24.                 }
  25.  
  26.                 reader.close();
  27.             }
  28.             catch (Exception e)
  29.             {
  30.                 System.err.println("Error loading source code: " + name);
  31.                 e.printStackTrace();
  32.             }
  33.  
  34.             return source.toString();
  35.         }
  36.  
  37.     /**
  38.      * @return An array of all the lines of a file
  39.      */
  40.     public static String[] readAllLines(String name)
  41.     {
  42.         return readFromFile(name).split("\n");
  43.     }
  44. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top