Your Ad Here

Posted By

ctran on 07/16/07


Tagged

java fgets


Versions (?)

fgets


 / Published in: Java
 

Read the content of the given file and return it as tring.

  1. /**
  2.   * Read the content of the given file and return it as tring.
  3.   *
  4.   * @param filePath
  5.   * the name of the file to open.
  6.   */
  7. public static String fgets(String filePath) throws java.io.IOException {
  8. BufferedReader reader = new BufferedReader(new FileReader(filePath));
  9. try {
  10. StringBuffer fileData = new StringBuffer(1000);
  11. char[] buf = new char[1024];
  12. int numRead = 0;
  13.  
  14. while ((numRead = reader.read(buf)) != -1) {
  15. fileData.append(buf, 0, numRead);
  16. }
  17.  
  18. return fileData.toString();
  19. } finally {
  20. reader.close();
  21. }
  22. }

Report this snippet  

You need to login to post a comment.