List of utility methods to do File Read
String | getFileContentFromClasspath(String pathToFile) TODO return toString(getFileFromClasspath(pathToFile));
|
HashMap | getFileContentIntoStrCategoriesDictionary(String fileName) get File Content Into Str Categories Dictionary FileReader file; String line = ""; HashMap<String, Integer> dict = new HashMap<String, Integer>(); try { file = new FileReader(fileName); BufferedReader reader = new BufferedReader(file); try { while ((line = reader.readLine()) != null) { ... |
long | getFileContentLength(String filename) Returns the content length of the file named filename as long .
return (new File(filename)).length(); |
List | getFileContentList(String filenamePath) Utility method to get the file content, any version of this can be adapted, this is just one way of achieving the result. InputStream is; List<String> lines = new ArrayList<String>(); try { is = new FileInputStream(new File(filenamePath)); DataInputStream in = new DataInputStream(is); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; while ((strLine = br.readLine()) != null) { ... |
String | getFileContentsAsString(@Nonnull final File file) Gets the contents of a File as a String . checkNotNull(file, "file cannot be null."); if (!file.exists()) { throw new IOException("File " + file + " does not exist"); if (!file.canRead()) { throw new IOException("Cannot read file " + file); if (file.isDirectory()) { ... |
List | getFileContentWithoutCRNL(File f, int linesPerElement, int[] setSizes) get File Content Without CRNL List<Set<String>> setList = new ArrayList<Set<String>>(); List<String> lineList = new ArrayList<String>(); List<String> elementList = new ArrayList<String>(); BufferedReader input = null; try { input = new BufferedReader(new InputStreamReader(new FileInputStream(f), "UTF-8")); String s = null; while ((s = input.readLine()) != null) { ... |