Giuseppe499

FileUtil.java

Oct 27th, 2015
142
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

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×