增加ICP调用第三方API chinaz 查询并存储结果到数据库,批量查询,文件查询,文件查询导出 CN-664
This commit is contained in:
@@ -14,36 +14,28 @@ import java.util.List;
|
||||
public class FileUtils {
|
||||
private static final Logger LOG = Logger.getLogger(FileUtils.class);
|
||||
|
||||
public static List<String> readTxtFileIntoStringArrList(String filePath)
|
||||
{
|
||||
public static List<String> readTxtFileIntoStringArrList(String filePath) {
|
||||
List<String> list = new ArrayList<>();
|
||||
try
|
||||
{
|
||||
try {
|
||||
String encoding = "GBK";
|
||||
File file = new File(filePath);
|
||||
if (file.isFile() && file.exists())
|
||||
{ // 判断文件是否存在
|
||||
if (file.isFile() && file.exists()) { // 判断文件是否存在
|
||||
InputStreamReader read = new InputStreamReader(
|
||||
new FileInputStream(file), encoding);
|
||||
BufferedReader bufferedReader = new BufferedReader(read);
|
||||
String lineTxt = null;
|
||||
|
||||
while ((lineTxt = bufferedReader.readLine()) != null)
|
||||
{
|
||||
while ((lineTxt = bufferedReader.readLine()) != null) {
|
||||
if (!lineTxt.equals("")) {
|
||||
list.add(lineTxt.trim());
|
||||
}
|
||||
}
|
||||
bufferedReader.close();
|
||||
read.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
System.out.println("Can not find file: " + filePath);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error occurred in Function 'readTxtFileIntoStringArrList'");
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -51,32 +43,31 @@ public class FileUtils {
|
||||
return list;
|
||||
}
|
||||
|
||||
public static List<String> getBatchLineReadIn(BufferedReader bufferedReader, int batchSize){
|
||||
public static List<String> getBatchLineReadIn(BufferedReader bufferedReader, int batchSize) {
|
||||
List<String> list = new ArrayList<>();
|
||||
String lineTxt;
|
||||
try{
|
||||
while ((lineTxt = bufferedReader.readLine()) != null && list.size()<batchSize)
|
||||
{
|
||||
try {
|
||||
while ((lineTxt = bufferedReader.readLine()) != null && list.size() < batchSize) {
|
||||
if (!lineTxt.equals("")) {
|
||||
list.add(lineTxt.trim());
|
||||
}
|
||||
}
|
||||
} catch (IOException e){
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static void createFile(File filePath, String fileName){
|
||||
public static void createFile(File filePath, String fileName) {
|
||||
try {
|
||||
File file = new File(filePath.toString() + "/" + fileName);
|
||||
|
||||
if (!filePath.exists()){
|
||||
if (!filePath.exists()) {
|
||||
filePath.mkdirs();
|
||||
}
|
||||
|
||||
boolean isCreate = file.createNewFile();
|
||||
if (isCreate){
|
||||
if (isCreate) {
|
||||
LOG.info("File " + fileName + " is created.");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
@@ -85,10 +76,10 @@ public class FileUtils {
|
||||
|
||||
}
|
||||
|
||||
public static void createFile(File file){
|
||||
public static void createFile(File file) {
|
||||
try {
|
||||
boolean isCreate = file.createNewFile();
|
||||
if (isCreate){
|
||||
if (isCreate) {
|
||||
LOG.info("File " + file + " is created.");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
@@ -121,20 +112,20 @@ public class FileUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static String getFileName(File file){
|
||||
public static String getFileName(File file) {
|
||||
String[] tmp = file.toString().split("/");
|
||||
String fileName = tmp[tmp.length-1];
|
||||
String fileName = tmp[tmp.length - 1];
|
||||
return fileName;
|
||||
}
|
||||
|
||||
|
||||
public static void writerClose(OutputStreamWriter outWriter, OutputStream outStream) throws IOException {
|
||||
public static void writerClose(OutputStreamWriter outWriter, OutputStream outStream) throws IOException {
|
||||
assert outWriter != null;
|
||||
outWriter.close();
|
||||
outStream.close();
|
||||
}
|
||||
|
||||
public static void readerClose(BufferedReader bufferedReader, InputStreamReader inputStreamReader) throws IOException {
|
||||
public static void readerClose(BufferedReader bufferedReader, InputStreamReader inputStreamReader) throws IOException {
|
||||
assert inputStreamReader != null;
|
||||
bufferedReader.close();
|
||||
inputStreamReader.close();
|
||||
@@ -142,14 +133,13 @@ public class FileUtils {
|
||||
|
||||
//执行cmd命令,获取返回结果
|
||||
public static String execCMD(String command) {
|
||||
StringBuilder sb =new StringBuilder();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
try {
|
||||
Process process=Runtime.getRuntime().exec(command);
|
||||
BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||
Process process = Runtime.getRuntime().exec(command);
|
||||
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||
String line;
|
||||
while((line=bufferedReader.readLine())!=null)
|
||||
{
|
||||
sb.append(line+"\n");
|
||||
while ((line = bufferedReader.readLine()) != null) {
|
||||
sb.append(line + "\n");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return e.toString();
|
||||
@@ -157,9 +147,9 @@ public class FileUtils {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static Long getFileLineNum(File file){
|
||||
public static Long getFileLineNum(File file) {
|
||||
Long num = 0L;
|
||||
if (!file.exists()){
|
||||
if (!file.exists()) {
|
||||
LOG.error("File not exist: " + file.toString());
|
||||
} else {
|
||||
String res = FileUtils.execCMD("wc -l " + file.toString());
|
||||
@@ -194,4 +184,12 @@ public class FileUtils {
|
||||
}
|
||||
return lengthDomain;
|
||||
}
|
||||
|
||||
public static String formatPath(String path) {
|
||||
path = path.replace("\\\\", "");
|
||||
path = path.replace("//", "");
|
||||
|
||||
return path;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user