com.alibaba.schedulerx.worker.util.FileUtils Maven / Gradle / Ivy
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();
}
}