Skip to content

Instantly share code, notes, and snippets.

@hacksoldier
Last active September 28, 2015 09:08
Show Gist options
  • Select an option

  • Save hacksoldier/293c7800760ba3ea00b0 to your computer and use it in GitHub Desktop.

Select an option

Save hacksoldier/293c7800760ba3ea00b0 to your computer and use it in GitHub Desktop.
public void readFileFromDisk (String path, String fileName){
try{
bufferReader = new BufferedReader(new FileReader("C:\\dati\\fileDiTest.txt"));
StringBuilder sb = new StringBuilder();
String line = bufferReader.readLine();
while (line != null) {
sb.append(line);
sb.append(System.lineSeparator());
line = bufferReader.readLine();
}
String everything = sb.toString();
log.debug("everything: " + everything);
} catch (FileNotFoundException fileNotFoundException) {
log.error("Error in readFileFromDisk - File not foud", fileNotFoundException);
} catch (IOException ioe){
log.error("Error in readFileFromDisk - Generic i/o error", ioe);
} finally {
if (bufferReader != null) {
bufferReader.close;
}
}
}
//call example: readFileOnDisk("C:\\dati\\", "fileTest.txt");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment