Android Utililty Methods Text File Read

List of utility methods to do Text File Read

Description

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

Method

StringreadFile(String filePath)
read File
String result = new String();
FileInputStream fstream = new FileInputStream(filePath);
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
while ((strLine = br.readLine()) != null) {
    result += strLine + "\n";
in.close();
return result;
StringreadFile(String filename)
Read a file into a string
StringBuffer fileData = new StringBuffer(1000);
BufferedReader reader = new BufferedReader(new FileReader(filename));
char[] buf = new char[1024];
int numRead = 0;
while ((numRead = reader.read(buf)) != -1) {
    String readData = String.valueOf(buf, 0, numRead);
    fileData.append(readData);
    buf = new char[1024];
...
SetreadFile(String path)
read File
Set<String> set = new HashSet<String>();
try {
    BufferedReader br = new BufferedReader(new FileReader(path));
    String line = null;
    while ((line = br.readLine()) != null) {
        set.add(line.trim());
    br.close();
...
StringreadFileAsString(File file)
read File As String
StringBuffer fStr = new StringBuffer();
try {
    InputStream is = new FileInputStream(file);
    if (file.getName().endsWith(".gz")) {
        is = new GZIPInputStream(is);
    BufferedReader reader = new BufferedReader(
            new InputStreamReader(is));
...
StringreadFileAsString(File file, String charset)
read File As String
StringBuffer fStr = new StringBuffer();
try {
    InputStream is = new FileInputStream(file);
    if (file.getName().endsWith(".gz")) {
        is = new GZIPInputStream(is);
    BufferedReader reader = new BufferedReader(
            new InputStreamReader(is, charset));
...
StringreadFileAsString(String filename)
read File As String
if (filename.startsWith(SERIALPREFIX)) {
    filename = serialFileName(filename);
return readFileAsString(new File(filename));
ArrayDequereadFileLineByLine(File file)
Reads file and returns contents as ArrayDeque, where each element is a line of the file
String filePath = file.getAbsolutePath();
FileInputStream fstream = new FileInputStream(filePath);
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
ArrayDeque<String> forReturn = new ArrayDeque<String>();
try {
    while ((strLine = br.readLine()) != null) {
...
ListreadFree(File file)
read Free
List<String> archive = new ArrayList<String>();
BufferedReader reader = new BufferedReader(new FileReader(file));
String s;
do {
    s = reader.readLine();
    if (s != null) {
        archive.add(s);
} while (s != null);
reader.close();
return archive;
StringreadFromFile(File file)
read From File
String result = "";
try {
    BufferedReader in = new BufferedReader(new InputStreamReader(
            file.toURI().toURL().openStream()));
    String inputLine = in.readLine();
    while (inputLine != null) {
        result += inputLine + "\n";
        inputLine = in.readLine();
...
StringreadFull(String path)
read Full
return new String(Files.readAllBytes(Paths.get(path)),
        Charset.defaultCharset());