1.string-json
/**
* string转换json对象和第二个没区别
*/
JSONObject jsonObject = JSONObject.parseObject(string);
String heatCompany = jsonObject.getString("com_code");
/**
* json字符串转化为对象
*/
String jsonString = "{name:'Antony',age:'12',sex:'male',telephone:'88888'}";
Staff staff = JSON.parseObject(jsonString, Staff.class);
System.out.println(staff.toString());
/**
* 对象转化为json字符串
*/
String jsonStr = JSON.toJSONString(staff);
System.out.println(jsonStr);
2.log日志的使用
private final Logger logger = LoggerFactory.getLogger(this.getClass());
logger.info("进入查询`````````````" + json);
3.IO流
/**
java程序---本地
*/
FileOutputStream fileOutputStream = new FileOutputStream("d:\\text.txt");//字符流,第二参数true,续写,默认为false。重写
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fileOutputStream,"utf-8");//子节
BufferedWriter bufferedWriter = new BufferedWriter(outputStreamWriter);//缓冲
writer.write("要输入的xml字符串");
writer.flush();
writer.close();
4.定时任务
@Configuration //1.主要用于标记配置类,兼备Component的效果。
@EnableScheduling // 2.开启定时任务
public class UploadAccountFile {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
private Environment env;
@Autowired
private RongShengHeat rongShengHeat;
@Scheduled(cron = "0 0 1 * * ?")//每小时会触发一次(秒 分 时 天 月 星?每星期会触发 *每天都会出发 都是匹配任意值的作用)
private void uploadAccountFile() {
String[] regist = rongShengHeat.regist();
for (String com_code : regist) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
String nowDateString = sdf.format(new Date());
String ip = env.getProperty("reli." + com_code + "ftp.ip");
String port = env.getProperty("reli." + com_code + "ftp.port");
String username = env.getProperty("reli." + com_code + "ftp.username");
String password = env.getProperty("reli." + com_code + "ftp.password");
// 文件名
String fileName = env.getProperty("reli." + com_code + "ftp.file-pre-name") + nowDateString + ".txt";
// 文件目录
String fileURL = AccountFileUrlConf.PARENT_URL + com_code + "/" + nowDateString;
File file = new File(fileURL + "/" + fileName);
// 如果不存在,创建空对账文件
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
logger.info("上传对账文件:" + fileURL + "/" + fileName + "\r\nftp信息==ip:" + ip + "==port:" + "==username:" + username + "==password:" + password);
upload(file, fileName, ip, port, username, password);
}
}