Android Text File Read getFileResourceText(String path)

Here you can find the source of getFileResourceText(String path)

Description

Gets the text from the URL resource.

Parameter

Parameter Description
path the resource's file path

Exception

Parameter Description

Return

the resource's text

Declaration

public static String getFileResourceText(String path)
        throws IOException 

Method Source Code

//package com.java2s;
import java.io.BufferedReader;

import java.io.FileReader;

import java.io.IOException;

public class Main {
    private static final String NEW_LINE = "\n";

    /**//from   www  .  j  a  v  a 2  s  .com
     * Gets the text from the URL resource.
     * <p/>
     *
     * @param path the resource's file path
     * @return the resource's text
     * @throws java.io.IOException if the resource was not found
     */
    public static String getFileResourceText(String path)
            throws IOException {
        BufferedReader fileReader = null;
        StringBuilder stringBuilder = new StringBuilder();
        try {
            fileReader = new BufferedReader(new FileReader(path));
            String line = null;
            while ((line = fileReader.readLine()) != null) {
                stringBuilder.append(line);
                stringBuilder.append(NEW_LINE);
            }
        } finally {
            if (fileReader != null) {
                fileReader.close();
            }
        }
        return stringBuilder.toString();
    }
}

Related

  1. fileToListByLine(String fileName)
  2. fileToSet(final String dirname, final String filename, final Set set)
  3. getFileContent(File file)
  4. getFileContent(File file, String charSet)
  5. read(File file)
  6. read(File file)
  7. read(File file, boolean raw)
  8. read(String file)