Created
January 30, 2014 12:15
-
-
Save aikchun/8707289 to your computer and use it in GitHub Desktop.
Read text file java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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