Skip to content

Instantly share code, notes, and snippets.

@duguying
Last active August 29, 2015 14:17
Show Gist options
  • Save duguying/29dd6af321958c6193d6 to your computer and use it in GitHub Desktop.
Save duguying/29dd6af321958c6193d6 to your computer and use it in GitHub Desktop.
read file content into string
private String readFileAsString(String filePath) throws IOException {
StringBuffer fileData = new StringBuffer();
BufferedReader reader = new BufferedReader(
new FileReader(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);
}
reader.close();
return fileData.toString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment