Skip to content

Instantly share code, notes, and snippets.

@aikchun
Created January 30, 2014 12:15
Show Gist options
  • Save aikchun/8707289 to your computer and use it in GitHub Desktop.
Save aikchun/8707289 to your computer and use it in GitHub Desktop.
Read text file java
public static String readTextFile () {
String fileContent = "";
BufferedReader br = null; ;
try {
br = new BufferedReader (new FileReader("TextFile.txt"));
StringBuilder sb = new StringBuilder();
String fileLine = "";
while ((fileLine = br.readLine()) != null) {
System.out.println(fileLine);
sb.append(fileLine);
sb.append(System.lineSeparator());
}
fileContent = sb.toString();
br.close();
} catch (IOException ioe) {
ioe.getMessage();
}
return fileContent;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment