Posted By

studioevoque on 11/01/10


Tagged

java io


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

ivoxiras


Read file to string


 / Published in: Java
 

  1. private String readFile(String pathname) throws IOException {
  2. StringBuilder stringBuilder = new StringBuilder();
  3. Scanner scanner = new Scanner(new File(pathname));
  4.  
  5. try {
  6. while(scanner.hasNextLine()) {
  7. stringBuilder.append(scanner.nextLine() + "\n");
  8. }
  9. } finally {
  10. scanner.close();
  11. }
  12. return stringBuilder.toString();
  13. }

Report this snippet  

You need to login to post a comment.