Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import android.util.Log;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;

public class Main {
    private static final String LOG_TAG = "SmartBandLogger";
    private static final String CLASS = "FileUtils";

    public static int getFileLines(File file) {
        if (!file.canRead() || !file.isFile()) {
            Log.w(LOG_TAG, CLASS + ": getLinesInFile: invalid file.");
            return -1;
        }

        int lines = 0;
        try {
            BufferedReader reader = new BufferedReader(new FileReader(file));
            while (reader.readLine() != null)
                lines++;
            reader.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

        return lines;
    }
}