Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

public class Main {
    /**
     *  Method to find the number of files from a particular folder on the device.
     */
    public static int findNumberOfFiles(String dFolderPath) throws InterruptedException {
        int numOfFiles = 0;
        Thread.sleep(500);
        try {
            ProcessBuilder process = new ProcessBuilder("adb", "shell", "ls", dFolderPath, "|", "wc", "-l");
            Process p = process.start();
            //Thread.sleep(5000);
            BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
            String line = null;
            p.waitFor();
            while ((line = br.readLine()) != null) {
                if (!line.equals(""))
                    numOfFiles = Integer.parseInt(line);
            }
        } catch (Exception e) {
            System.out.println(e);
        }
        return numOfFiles;
    }
}