|
|
|
@ -1,11 +1,17 @@
|
|
|
|
|
package org.springblade.common.utils; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.lang.UUID; |
|
|
|
|
import org.slf4j.Logger; |
|
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
import org.springblade.common.constant.CommonConstant; |
|
|
|
|
|
|
|
|
|
import java.io.*; |
|
|
|
|
import java.io.BufferedReader; |
|
|
|
|
import java.io.File; |
|
|
|
|
import java.io.FileWriter; |
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.io.InputStreamReader; |
|
|
|
|
import java.io.Writer; |
|
|
|
|
import java.net.HttpURLConnection; |
|
|
|
|
import java.net.URL; |
|
|
|
|
import java.util.Calendar; |
|
|
|
@ -29,16 +35,17 @@ public class FileLogsUtil {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String imgPath = CommonConstant.SYSTEMFILEPATH + "logs/"; |
|
|
|
|
//根据当前时间 按照 年/月/日 创建一个文件
|
|
|
|
|
// 根据当前时间 按照 年/月/日 创建一个文件
|
|
|
|
|
imgPath = imgPath + dataString; |
|
|
|
|
|
|
|
|
|
// 判断文件夹是否存在
|
|
|
|
|
// 判断文件夹是否存在
|
|
|
|
|
File imgPathFile = new File(imgPath); |
|
|
|
|
if (!imgPathFile.exists()) { |
|
|
|
|
imgPathFile.mkdirs(); |
|
|
|
|
} |
|
|
|
|
// 按照年-月-日 创建一个字符串
|
|
|
|
|
String fileName = System.currentTimeMillis() + ".log"; |
|
|
|
|
// 使用 uuid 作为文件名 确保文件唯一
|
|
|
|
|
String fileName = UUID.randomUUID().toString() + ".log"; |
|
|
|
|
|
|
|
|
|
Writer writer = null; |
|
|
|
|
try { |
|
|
|
@ -67,7 +74,7 @@ public class FileLogsUtil {
|
|
|
|
|
|
|
|
|
|
public static String loadFileContent(String urlString) { |
|
|
|
|
try { |
|
|
|
|
log.info(">>>> 开始下载 {}",urlString); |
|
|
|
|
log.info(">>>> 开始下载 {}", urlString); |
|
|
|
|
URL url = new URL(urlString); |
|
|
|
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection(); |
|
|
|
|
connection.setRequestMethod("GET"); |
|
|
|
@ -78,7 +85,7 @@ public class FileLogsUtil {
|
|
|
|
|
content.append(inputLine); |
|
|
|
|
} |
|
|
|
|
in.close(); |
|
|
|
|
log.info(">>>> 结束下载 {}",urlString); |
|
|
|
|
log.info(">>>> 结束下载 {}", urlString); |
|
|
|
|
return content.toString(); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
@ -90,12 +97,12 @@ public class FileLogsUtil {
|
|
|
|
|
|
|
|
|
|
StringBuilder stringBuffer = new StringBuilder(); |
|
|
|
|
Calendar calendar = Calendar.getInstance(); |
|
|
|
|
calendar.setTime(date); //放入Date类型数据
|
|
|
|
|
//获取年份
|
|
|
|
|
calendar.setTime(date); // 放入Date类型数据
|
|
|
|
|
// 获取年份
|
|
|
|
|
stringBuffer.append(calendar.get(Calendar.YEAR)).append("/"); |
|
|
|
|
//获取月份
|
|
|
|
|
// 获取月份
|
|
|
|
|
stringBuffer.append(calendar.get(Calendar.MONTH) + 1).append("/"); |
|
|
|
|
//获取日份
|
|
|
|
|
// 获取日份
|
|
|
|
|
stringBuffer.append(calendar.get(Calendar.DATE)).append("/"); |
|
|
|
|
return stringBuffer.toString(); |
|
|
|
|
|
|
|
|
|