You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
112 lines
3.6 KiB
112 lines
3.6 KiB
package com.mh.user; |
|
|
|
import com.mh.user.utils.ExchangeStringUtil; |
|
import org.jsoup.Jsoup; |
|
import org.jsoup.nodes.Document; |
|
import org.jsoup.nodes.Element; |
|
import org.jsoup.select.Elements; |
|
|
|
import java.io.BufferedReader; |
|
import java.io.FileReader; |
|
import java.io.IOException; |
|
import java.io.InputStream; |
|
import java.net.URL; |
|
import java.nio.file.Files; |
|
import java.nio.file.Path; |
|
import java.nio.file.Paths; |
|
import java.nio.file.StandardCopyOption; |
|
import java.text.ParseException; |
|
import java.text.SimpleDateFormat; |
|
import java.util.ArrayList; |
|
import java.util.Date; |
|
import java.util.List; |
|
|
|
/** |
|
* @author ljf |
|
* @title : |
|
* @description : |
|
* @updateTime 2020-03-14 |
|
* @throws : |
|
*/ |
|
public class SysUserTest { |
|
|
|
private static final SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
public static void main(String[] args) throws ParseException, IOException { |
|
String dateStr = ""; |
|
Date date = new Date(); |
|
if (ExchangeStringUtil.isInDate(date, "00:00:00", "00:00:30")) { |
|
dateStr = sdf1.format(date); |
|
dateStr = dateStr.substring(0, 17) + "00"; |
|
|
|
System.out.println("插入时间00" + dateStr); |
|
} else if (ExchangeStringUtil.isInDate(date, "00:00:30", "00:00:59")) { |
|
dateStr = sdf1.format(date); |
|
dateStr = dateStr.substring(0, 17) + "30"; |
|
|
|
System.out.println("插入时间30" + dateStr); |
|
} |
|
// // 读取TXT文件中的HTML内容 |
|
// String htmlContent = readFile("C:/Users/MH/Desktop/getAir.txt"); |
|
// |
|
// // 使用Jsoup解析HTML |
|
// Document doc = Jsoup.parse(htmlContent); |
|
// |
|
// // 提取所有的img标签 |
|
// Elements imgElements = doc.select("img"); |
|
// |
|
// // 存储img标签的src属性 |
|
// List<String> imgSrcs = new ArrayList<>(); |
|
// for (Element img : imgElements) { |
|
// if (img.attr("src").startsWith("//")) { |
|
// imgSrcs.add("http:" + img.attr("src")); |
|
// } else { |
|
// imgSrcs.add(img.attr("src")); |
|
// } |
|
// } |
|
// for (int i = 0; i < imgSrcs.size(); i++) { |
|
// // 指定要保存的本地文件路径 |
|
// Path localFilePath = Paths.get("D:/ljf/images/"+i+".jpg"); |
|
// |
|
// // 下载图片 |
|
// try { |
|
// downloadImageToFile(imgSrcs.get(i), localFilePath); |
|
// } catch (IOException e) { |
|
// continue; |
|
// } |
|
// } |
|
} |
|
|
|
private static String readFile(String filePath) throws IOException { |
|
StringBuilder contentBuilder = new StringBuilder(); |
|
|
|
try (BufferedReader br = new BufferedReader(new FileReader(filePath))) { |
|
String currentLine; |
|
|
|
while ((currentLine = br.readLine()) != null) { |
|
contentBuilder.append(currentLine).append("\n"); |
|
} |
|
} |
|
|
|
return contentBuilder.toString(); |
|
} |
|
|
|
/** |
|
* 从给定的URL下载图片并保存到指定的本地路径。 |
|
* |
|
* @param urlStr 图片URL地址 |
|
* @param localPath 本地文件路径 |
|
* @throws IOException 如果发生IO错误 |
|
*/ |
|
private static void downloadImageToFile(String urlStr, Path localPath) throws IOException { |
|
// 打开URL连接 |
|
URL url = new URL(urlStr); |
|
try (InputStream in = url.openStream()) { |
|
// 创建文件的父目录(如果不存在) |
|
Files.createDirectories(localPath.getParent()); |
|
|
|
// 将输入流的内容复制到本地文件 |
|
Files.copy(in, localPath, StandardCopyOption.REPLACE_EXISTING); |
|
} |
|
} |
|
|
|
}
|
|
|