Created
April 9, 2017 06:54
-
-
Save evoxtorm/0d7ac395dec650e05146442dbdc0461d to your computer and use it in GitHub Desktop.
code for reading a text file and returning it's length.
This file contains 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
import java.io.*; | |
public class Test { | |
public static void main(String [] args) { | |
String fileName = "abc.txt"; | |
String line = null; | |
try { | |
FileReader fileReader = | |
new FileReader(fileName); | |
BufferedReader bufferedReader = | |
new BufferedReader(fileReader); | |
while((line = bufferedReader.readLine()) != null) { | |
System.out.println(line); | |
} | |
bufferedReader.close(); | |
System.out.println("total length of the file :" + fileName.length()); | |
} | |
catch(FileNotFoundException ex) { | |
System.out.println( | |
"Unable to open file '" + | |
fileName + "'"); | |
} | |
catch(IOException ex) { | |
System.out.println( | |
"Error reading file '" | |
+ fileName + "'"); | |
// Or we could just do this: | |
// ex.printStackTrace(); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment