当前位置: 首页 > news >正文

开发一个网站需要的技术刚刚中国突然宣布

开发一个网站需要的技术,刚刚中国突然宣布,营销型网站建设策划,临城网站下面的demo当中 &#xff0c;是将json文件放到了zip包当中。如果不需要&#xff0c;可以拿掉。 1、生成对象JSON文件 public static void crateJson() {try {String orcPath "D:\\doc\\ts_service_orchestration.json";// 对象集合或者对象都可以List<DataPO>…

下面的demo当中 ,是将json文件放到了zip包当中。如果不需要,可以拿掉。

1、生成对象JSON文件

	public static void crateJson() {try {String orcPath = "D:\\doc\\ts_service_orchestration.json";// 对象集合或者对象都可以List<DataPO> dataPOList = new ArrayList<>();String jsonString = JSONObject.toJSONString(dataPOList);// 生成json文件tempFile(orcPath, jsonString);FileInputStream fileInputStream = null;int length;byte[] b = new byte[1024];int len;String path =  "D:\\doc\\压缩包.zip";File zipfile = new File(path);if (!zipfile.exists()) {zipfile.createNewFile();}// 将json文件放入到压缩包当中// key 文件名称, value 文件地址HashMap<String, String> maps = new HashMap<>();maps.put("ts_service_orchestration.json", orcPath);ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipfile));for (Map.Entry<String, String> entry : maps.entrySet()) {File newFile = new File(entry.getValue());fileInputStream = new FileInputStream(newFile);out.putNextEntry(new ZipEntry(entry.getKey()));while ((len = fileInputStream.read(b)) > 0){out.write(b, 0, len);}out.closeEntry();fileInputStream.close();}out.close();// delete jsonFilenew File(orcPath).delete();}catch (Exception e){e.printStackTrace();}}public static void tempFile(String filePath, String jsonData) throws IOException {// 保证创建一个新文件File file = new File(filePath);if (!file.getParentFile().exists()) { // 如果父目录不存在,创建父目录file.getParentFile().mkdirs();}if (file.exists()) { // 如果已存在,删除旧文件file.delete();}file.createNewFile();// 格式化json字符串jsonData = JsonUtil.formatJson(jsonData);// 将格式化后的字符串写入文件Writer write = new OutputStreamWriter(new FileOutputStream(file), "UTF-8");write.write(jsonData);write.flush();write.close();}

2、读取json文件

	public static void readJson(){try {// 转为压缩文件流ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream("D:\\doc\\压缩包.zip"), Charset.forName("gbk"));ZipEntry zipEntry = null;while ((zipEntry = zipInputStream.getNextEntry()) != null) {if (!zipEntry.isDirectory() && zipEntry.getName().endsWith(".json")) {// Read the Excel file from the Zip entryByteArrayOutputStream outputStream = new ByteArrayOutputStream();byte[] buffer = new byte[4096];int length = -1;while ((length = zipInputStream.read(buffer)) != -1) {outputStream.write(buffer, 0, length);}outputStream.close();tempReadFile(outputStream);zipInputStream.closeEntry();}}zipInputStream.close();} catch (IOException e) {e.printStackTrace();}}public static void tempReadFile(ByteArrayOutputStream outputStream) throws IOException {String jsonStr = "";Reader reader = new InputStreamReader(new ByteArrayInputStream(outputStream.toByteArray()),"utf-8");int ch = 0;StringBuffer sb = new StringBuffer();while ((ch = reader.read()) != -1) {sb.append((char) ch);}reader.close();jsonStr = sb.toString();// 这里注意,如果是json文件当中是对象集合的话可以这样写,但是如果是对象的话,这样转换是会出错的。JSONArray array = JSONObject.parseArray(jsonStr);for (Object o : array) {JSONObject jsonObject = (JSONObject)o;System.out.println(jsonObject);}System.out.println("=================================================================");}
http://www.laogonggong.com/news/49432.html

相关文章:

  • 海外网站代购的方案百度推广总部电话
  • 今日西安核酸最新消息一个具体网站的seo优化方案
  • 义乌建设局网站活动推广方案
  • 北京网站建设开发各大搜索引擎提交入口
  • 日本网站图片做淘宝代购郑州seo优化公司
  • 做网站月入7000外贸新手怎样用谷歌找客户
  • 网站后台发表文章新网站推广方法
  • 如何上传文件到自己的网站龙岗网站制作
  • 专业微信网站建设seo优化前景
  • 做网站要多少钱seo是什么意思怎么解决
  • 网站建设公司 深圳如何做网站推广的策略
  • 莱芜都市网二手房结构优化设计
  • 去除 做网站就用建站之星app推广拉新
  • 哪家网站专做女性服装百度排名优化
  • 设置网站标签泰安百度推广代理
  • 内蒙古做网站的公司seo关键技术有哪些
  • 网站开发专业的比较成功的网络营销案例
  • seo网站建设步骤正规软件开发培训学校
  • 武汉做网站哪家公司好十大微商推广平台
  • 做网站42类商标怎么选小类seo综合查询工具
  • 腾讯云网站安全认证新网站seo
  • 广州学校网站建设水果营销软文
  • 怎么能看出别人的网站是哪一家做日本站外推广网站
  • 口碑好网站建设公司电话吉林网站推广公司
  • 网站推广策划方案google国际版
  • 舟山建站关键词搜索推广排行榜
  • 长沙模板建站服务公司seo刷词工具在线
  • 网站建设 单一来源长春做网站推广的公司
  • 21ic项目外包平台如何进行搜索引擎优化?
  • 创办网站域名seo论坛