Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Equivalent to Files.readAllLines() but, works way faster
- */
- public static List<String> getFileLines(File f,boolean utf8)
- {
- BufferedReader reader = null;
- List<String> list = null;
- try
- {
- if(!utf8)
- {
- 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
- }
- else
- {
- reader = new BufferedReader(new InputStreamReader(new FileInputStream(f),StandardCharsets.UTF_8) );
- }
- list = new ArrayList();
- String s = reader.readLine();
- if(s != null)
- {
- list.add(s);
- }
- while(s != null)
- {
- s = reader.readLine();
- if(s != null)
- {
- list.add(s);
- }
- }
- }
- catch(Exception e)
- {
- e.printStackTrace();
- }
- finally
- {
- if(reader != null)
- {
- try
- {
- reader.close();
- } catch (IOException e)
- {
- System.out.println("Unable to Close InputStream this is bad");
- }
- }
- }
- return list;
- }
Advertisement
Add Comment
Please, Sign In to add comment