wuyouming666
2023-12-14 84bb4d6cb579ee49e9a28c7507eabdf793a3a21e
springboot-vue3/src/main/java/com/example/springboot/component/PlcPositioning2.java
@@ -10,53 +10,7 @@
import java.util.List;
public class PlcPositioning2 extends Thread {
    String name = "";
    Integer count = 0;
    public static String readFileToString(String filePath) throws IOException {
        File file = new File(filePath);
        return FileUtils.readFileToString(file, "UTF-8");
    }
    public void readValue() {
        String str = "";
        BufferedReader bufferedReader = null;
        FileInputStream fileInputStream;
        try {
            // 从文件中读取字节数据存入 fileInputStream
            fileInputStream = new FileInputStream("CanadaMes-ui/src/configuration/address.json");
            // 读取 fileInputStream 中字节并将其解码为字符
            InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "utf-8");
            // 提高读取效率,在 BufferedReader 内包装 InputStreamReader
            bufferedReader = new BufferedReader(inputStreamReader);
            String line = null;
            // 将 bufferedReader 内容一行一行赋值给str
            while ((line = bufferedReader.readLine()) != null) {
                str += line;
            }
            // 将str字符串格式转为json
            JSONObject jsonObject = new JSONObject(str);
            // 获取json中的值
            JSONArray address = jsonObject.getJSONArray("Positioning2");
            for (int i = 0; i < address.size(); i++) {
                JSONObject ress = (JSONObject) address.get(i);
                this.name = ress.getStr("name");
                this.count = ress.getInt("count");
                System.out.println("messageValues:" + this.name);
                System.out.println("messageValues:" + this.count);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    @Override
    public void run() {