FileTool.java
2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package com.example.demo.util.IO;
import com.example.demo.util.Date.DateUtil;
import com.example.demo.util.Helper;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.io.IOException;
public final class FileTool {
private final static String errorRootDirectory = "errorLogs";//错误的根目录名
private final static String xmlRootDirectory = "xmlLog"; //记录已收到的报文目录
private final static String Cherector = "UTF-8";
private final static String messageBakDir = "xmlFromImf";
/**
* 写入文件
* @param path 二级目录
* @param content 写入内容
* @param rightOrwrong 是写入错误记录目录还是记录目录
*/
public static void writeFile(String path,String content,boolean rightOrwrong){
StringBuffer stringBuffer = new StringBuffer();
if (rightOrwrong){
stringBuffer.append(xmlRootDirectory).append("/").append(path).append("/").append(DateUtil.getToday()).append("/").append(Helper.getUUID()).append(".log");
}else {
stringBuffer.append(errorRootDirectory).append("/").append(path).append("/").append(DateUtil.getToday()).append("/").append(Helper.getUUID()).append(".log");
}
File file = new File(stringBuffer.toString());
try{
FileUtils.writeStringToFile(file,content,Cherector);
}catch (IOException e){
e.printStackTrace();
}
}
public static void writeWaybill(String path,String content,String waybillNo){
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append(xmlRootDirectory).append("/").append(path).append("/").append(DateUtil.getToday()).append("/").append(waybillNo).append(".log");
File file = new File(stringBuffer.toString());
try{
FileUtils.writeStringToFile(file,content,Cherector);
}catch (IOException e){
e.printStackTrace();
}
}
public static void writeFileToBak(String content){
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append(messageBakDir).append("/").append(Helper.getUUID()).append(".log");
File file = new File(stringBuffer.toString());
try{
FileUtils.writeStringToFile(file,content,Cherector);
}catch (IOException e){
e.printStackTrace();
}
}
}