package com.shanghaichengdi.ghjgitem.util;

import java.io.File;
import java.io.FileOutputStream;
import java.nio.charset.StandardCharsets;

/**
 * @author gengaoliu
 */
public class FileUtil {

  public static void fileWrite(String path, String msg) throws Exception {
    File file = new File(path);
    if (!file.exists()) {
      file.createNewFile();
    }
    FileOutputStream out = new FileOutputStream(file, true);
    out.write(msg.getBytes(StandardCharsets.UTF_8));
    out.close();
  }

  public static void main(String[] args) throws Exception {
    FileUtil.fileWrite(
        "/Users/gengaoliu/test.txt",
        "{\"method\":\"OnEventNotify\",\"params\":{\"ability\":\"event_shipbayonet\",\"events\":[{\"data\":{\"dataType\":0,\"extendedParam\":{\"alarmType\":0,\"crossInfoIndexCode\":\"2009290001360219200\",\"crossInfoName\":\"北岸\",\"direction\":3001,\"imageUrls\":[\"/shipbayonet/pic/3066856/origin\",\"/shipbayonet/pic/3066857/origin\",\"/shipbayonet/pic/3066858/origin\",\"/shipbayonet/pic/3066859/origin\",\"/shipbayonet/pic/3066860/origin\",\"/shipbayonet/pic/3066861/origin\",\"/shipbayonet/pic/3066862/origin\"],\"passId\":278523,\"passTime\":\"2023-04-13T00:08:22.000+08:00\",\"shipName\":\"\",\"shipType\":0,\"speed\":6.4019999074935914}},\"eventId\":\"0cd52e89-c32f-4480-9498-6b5fd3d0c331\",\"eventType\":8405426177,\"happenTime\":\"2023-04-13 00:08:22\",\"srcIndex\":\"shipbayonetweb\",\"srcName\":\"shipbayonetweb\",\"srcType\":\"shipbayonetweb\",\"status\":0}],\"sendTime\":\"2023-04-13 00:09:07\"}}"
            + System.getProperty("line.separator"));
  }
}
