Skip to content

Instantly share code, notes, and snippets.

@prasincs
Created July 24, 2009 10:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prasincs/153967 to your computer and use it in GitHub Desktop.
Save prasincs/153967 to your computer and use it in GitHub Desktop.
/**
* @param filePath
* name of file to open. The file can reside
* anywhere in the classpath or absolute path path
*/
public static String readFileAsString(String filePath) throws java.io.IOException {
StringBuffer fileData = new StringBuffer(1000);
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(filePath)));
char[] buf = new char[1024];
int numRead = 0;
while ((numRead = reader.read(buf)) != -1) {
String readData = String.valueOf(buf, 0, numRead);
fileData.append(readData);
buf = new char[1024];
}
reader.close();
return fileData.toString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment