Advertisement
ManZzup

Untitled

Aug 12th, 2016
850
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.71 KB | None | 0 0
  1.      //Get file from resources folder
  2.             ClassLoader classLoader = getClass().getClassLoader();
  3.             URI filepath = new URI(classLoader.getResource(path).toString());
  4.  
  5.             File file = new File(filepath);
  6.  
  7.             Scanner scanner = new Scanner(file);
  8.  
  9.             while (scanner.hasNextLine()) {
  10.                 String line = scanner.nextLine();
  11.                 result.append(line).append("\n");
  12.             }
  13.  
  14.             scanner.close();
  15.  
  16.         } catch (IOException e) {
  17.             e.printStackTrace();
  18.         } catch(URISyntaxException e){
  19.             e.printStackTrace();
  20.         }
  21.  
  22.         return result.toString().replaceAll("\\n\\r|\\n|\\r|\\t|\\s{2,}","");
  23.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement