6°

Java base - common utiliy

1. Read the file on project

static String jsonFileName = "standard_return_bd.json";

ClassLoader classLoader = getClass().getClassLoader(); File file = new File(classLoader.getResource(jsonFileName).getFile()); String absolutePath = file.getAbsolutePath(); System.out.println(absolutePath);

// --common-io on build.gradle----------- implementation group: 'commons-io', name: 'commons-io', version: '2.6' // read file content String string = FileUtils.readFileToString(file, Charset.defaultCharset());

apache common-io

2. Fastjson to play with Object&JSON

// build.gradle
implementation ('com.alibaba:fastjson:1.2.47')

// String to Object ImageResult parsed = JSONObject.parseObject(jsonStr, ImageResult.class);

 

 

 

本文由【园领T】发布于开源中国,原文链接:https://my.oschina.net/joryqiao/blog/3157777

全部评论: 0

    我有话说: