Android BufferedReader Read readFileFolder(String filePath)

Here you can find the source of readFileFolder(String filePath)

Description

read File Folder

Declaration

public static void readFileFolder(String filePath) 

Method Source Code

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

public class Main {
    public static void readFileFolder(String filePath) {
        File file = new File(filePath);
        if (file.exists()) {
            if (file.isDirectory()) {
                System.out.println(file.getName());
                File[] files = file.listFiles();
                if (files != null && files.length > 0) {
                    for (File f : files) {
                        System.out.println(f.getName());
                        readFileFolder(f.getAbsolutePath());
                    }//from w w w .  j a  va  2  s  .  c om
                }
            } else {
                printFileContent(file.getAbsolutePath());
            }
        }
    }

    private static void printFileContent(String filePath) {
        File file = new File(filePath);
        BufferedReader reader = null;
        try {
            reader = new BufferedReader(new java.io.FileReader(file));
            String line = null;
            while ((line = reader.readLine()) != null) {
                System.out.println(line);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (reader != null) {
                    reader.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

Related

  1. getFileContent(File f)
  2. readFileAsString(File file)
  3. readStream(Reader r)
  4. readStringFromBufferedReader(BufferedReader br)
  5. toList(String fileName)