上传一个自己平时解析文件用到的工具类,想着以后要用到,搜来搜去太麻烦了,自用。感兴趣也可看看。
import org.apache.commons.lang3.time.DateUtils;
import org.mozilla.intl.chardet.nsDetector;
import org.mozilla.intl.chardet.nsICharsetDetectionObserver;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.text.ParseException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class DataFileTypeUtil {
private static boolean found = false;
private static String encoding = null;
/**
* 判断是否含有特殊字符
*
* @param str 要判断的字符串
* @return true为包含,false为不包含
*/
public static boolean isSpecialChar(String str) {
String regEx = "[ _`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。,、?]|\n|\r|\t";
Pattern p = Pattern.compile(regEx);
Matcher m = p.matcher(str);
return m.find();
}
/*