Advertisement
Guest User

Untitled

a guest
May 29th, 2015
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. String fileToRead = "path-to-file"; //path to file in the fs
  2. //reads the text file line by line
  3. BufferedReader reader = new BufferedReader(new FileReader(fileToRead));
  4. String curLine = null; //current line string
  5. StringBuilder strBuilder = new StringBuilder(); //using stringbuilder to slowly build the string by appending lines
  6.  
  7. while ((curLine = reader.readLine()) != null) { //while there are more lines
  8. strBuilder.append(curLine); //append lines to StringBuilder
  9. }
  10. String input = strBuilder.toString(); //converting strBuilder to string
  11. return input; //and return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement