Guest User

Untitled

a guest
Apr 26th, 2018
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. /**
  2. * Equivalent to Files.readAllLines() but, works way faster
  3. */
  4. public static List<String> getFileLines(File f,boolean utf8)
  5. {
  6. BufferedReader reader = null;
  7. List<String> list = null;
  8. try
  9. {
  10. if(!utf8)
  11. {
  12. reader = new BufferedReader(new FileReader(f));//says it's utf-8 but, the jvm actually specifies it even though the lang settings in a game might be different
  13. }
  14. else
  15. {
  16. reader = new BufferedReader(new InputStreamReader(new FileInputStream(f),StandardCharsets.UTF_8) );
  17. }
  18.  
  19. list = new ArrayList();
  20. String s = reader.readLine();
  21.  
  22. if(s != null)
  23. {
  24. list.add(s);
  25. }
  26.  
  27. while(s != null)
  28. {
  29. s = reader.readLine();
  30. if(s != null)
  31. {
  32. list.add(s);
  33. }
  34. }
  35. }
  36. catch(Exception e)
  37. {
  38. e.printStackTrace();
  39. }
  40. finally
  41. {
  42. if(reader != null)
  43. {
  44. try
  45. {
  46. reader.close();
  47. } catch (IOException e)
  48. {
  49. System.out.println("Unable to Close InputStream this is bad");
  50. }
  51. }
  52. }
  53.  
  54. return list;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment