Java Utililty Methods File Read

List of utility methods to do File Read

Description

The list of methods to do File Read are organized into topic(s).

Method

StringgetFileContentFromClasspath(String pathToFile)
TODO
return toString(getFileFromClasspath(pathToFile));
HashMapgetFileContentIntoStrCategoriesDictionary(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) {
...
longgetFileContentLength(String filename)
Returns the content length of the file named filename as long.
return (new File(filename)).length();
ListgetFileContentList(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) {
...
StringgetFileContentsAsString(@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) {
...