1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- package com.example.xiaoshiweixinback.business.utils;
- import com.alibaba.fastjson.JSONArray;
- import com.example.xiaoshiweixinback.XiaoshiWeixinbackApplication;
- import com.example.xiaoshiweixinback.entity.vo.PatentExportVO;
- import org.springframework.boot.system.ApplicationHome;
- import org.springframework.stereotype.Service;
- import java.io.*;
- import java.nio.charset.StandardCharsets;
- import java.util.List;
- /**
- * 解析配置utils
- *
- * @Author xiexiang
- * @Date 2023/6/2
- */
- @Service
- public class ExcuteConfigUtils {
- public static final String FILE_SEPARATOR = System.getProperty("file.separator");
- //解析配置utils
- public static String excuteConfigJson() {
- ApplicationHome ah = new ApplicationHome(XiaoshiWeixinbackApplication.class);
- File file = ah.getSource();
- String rootPath = file.getParentFile().toString() + FILE_SEPARATOR + "patentExport.json";
- BufferedReader reader = null;
- StringBuilder last = new StringBuilder();
- InputStreamReader inputStreamReader;
- try (FileInputStream fileInputStream = new FileInputStream(rootPath)) {
- inputStreamReader = new InputStreamReader(fileInputStream, StandardCharsets.UTF_8);
- reader = new BufferedReader(inputStreamReader);
- String tempString;
- while ((tempString = reader.readLine()) != null) {
- last.append(tempString);
- }
- reader.close();
- } catch (IOException e) {
- e.printStackTrace();
- } finally {
- if (reader != null) {
- try {
- reader.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- return last.toString();
- }
- //解析配置utils
- public static List<PatentExportVO> excuteConfigVO() {
- String config = ExcuteConfigUtils.excuteConfigJson();
- List<PatentExportVO> patentExportVOS = JSONArray.parseArray(config,PatentExportVO.class);
- return patentExportVOS;
- }
- }
|