All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.alibaba.schedulerx.worker.util.FileUtils Maven / Gradle / Ivy

There is a newer version: 1.12.2
Show newest version
package com.alibaba.schedulerx.worker.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;

import com.alibaba.schedulerx.worker.log.LogFactory;
import com.alibaba.schedulerx.worker.log.Logger;

/**
*
* @author xiaomeng.hxm
*/
public class FileUtils {
    private static final Logger LOGGER = LogFactory.getLogger(FileUtils.class);
    
    public static String readLine(String path) {
        String line = null;
        try {
            BufferedReader bf = new BufferedReader(new FileReader(path));
            line = bf.readLine();
            bf.close();
        } catch (Exception e) {
            LOGGER.error("", e);
        }
        return line;
    }

    public static String readLine(String path, String matchStr) {
        String line = null;
        try {
            BufferedReader bf = new BufferedReader(new FileReader(path));
            while ((line = bf.readLine()) != null) {
                if (line.contains(matchStr)) {
                    bf.close();
                    return line;
                }
            }
            bf.close();
        } catch (Exception e) {
            LOGGER.error("", e);
        }
        return null;
    }

    public static boolean isExist(String path) {
        File file = new File(path);
        return file.exists();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy