Skip to content

Instantly share code, notes, and snippets.

@carlosdlf
Created July 23, 2016 08:11
Show Gist options
  • Save carlosdlf/192356b01654430b2e4b4fcd01ba838c to your computer and use it in GitHub Desktop.
Save carlosdlf/192356b01654430b2e4b4fcd01ba838c to your computer and use it in GitHub Desktop.
public static StringBuilder readFile(File $f) throws IOException {
StringBuilder sb = new StringBuilder();
BufferedReader br = null;
try {
String sCurrentLine;
br = new BufferedReader(new FileReader($f));
while ((sCurrentLine = br.readLine()) != null) {
sb.append(sCurrentLine).append("\n");
}
} catch (IOException e) {
throw new IOException("Error leyendo archivo");
} finally {
try {
if (br != null)br.close();
} catch (IOException ex) {
throw new IOException("Error cerrando archivo");
}
}
return sb;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment