Skip to content

Instantly share code, notes, and snippets.

@xavivars
Created November 25, 2009 12:25
Show Gist options
  • Save xavivars/242671 to your computer and use it in GitHub Desktop.
Save xavivars/242671 to your computer and use it in GitHub Desktop.
private static String readFileAsString(String filePath) throws java.io.IOException{
byte[] buffer = new byte[(int) new File(filePath).length()];
FileInputStream f = new FileInputStream(filePath);
f.read(buffer);
return new String(buffer);
}
private static String readFileAsString(String filePath) throws java.io.IOException{
StringBuffer fileData = new StringBuffer(1000);
BufferedReader reader = new BufferedReader(new FileReader(filePath));
char[] buf = new char[1024];
int numRead=0;
while((numRead=reader.read(buf)) != -1){
fileData.append(buf, 0, numRead);
}
reader.close();
return fileData.toString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment