|
|
|
@ -1,6 +1,10 @@ |
|
|
|
package cn.chjyj.szwh.utils; |
|
|
|
|
|
|
|
import cn.chjyj.szwh.configure.EnvConfig; |
|
|
|
|
|
|
|
import java.io.*; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.Calendar; |
|
|
|
|
|
|
|
/** |
|
|
|
* 文件操作工具 |
|
|
|
@ -64,4 +68,60 @@ public class SzFileUtils { |
|
|
|
} |
|
|
|
return out; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 输入流创建文件 |
|
|
|
* @param inputStream |
|
|
|
* @param filename |
|
|
|
*/ |
|
|
|
public static void createFile(InputStream inputStream,String filename) { |
|
|
|
Calendar calendar = Calendar.getInstance(); |
|
|
|
//年月日格式
|
|
|
|
String folder = "json"+File.separator+calendar.get(1)+File.separator+calendar.get(2)+File.separator; |
|
|
|
String path= EnvConfig.yxDbConf()+File.separator+folder+filename+".json"; |
|
|
|
File fdFile = new File(folder); |
|
|
|
// 检查目录是否存在
|
|
|
|
if(!fdFile.exists()){ |
|
|
|
fdFile.mkdirs(); |
|
|
|
} |
|
|
|
int index; |
|
|
|
byte[] bytes = new byte[1024]; |
|
|
|
try { |
|
|
|
FileOutputStream jsonFile = new FileOutputStream(path); |
|
|
|
while ((index = inputStream.read(bytes)) != -1) { |
|
|
|
jsonFile.write(bytes, 0, index); |
|
|
|
jsonFile.flush(); |
|
|
|
} |
|
|
|
jsonFile.close(); |
|
|
|
inputStream.close(); |
|
|
|
}catch (Exception ex){ |
|
|
|
ex.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 返回json执行结果 |
|
|
|
* @param filename |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public static String readJson(String filename){ |
|
|
|
Calendar calendar = Calendar.getInstance(); |
|
|
|
//年月日格式
|
|
|
|
String folder = "json"+File.separator+calendar.get(1)+File.separator+calendar.get(2)+File.separator; |
|
|
|
String path= EnvConfig.yxDbConf()+File.separator+folder+filename+".json"; |
|
|
|
File fdFile = new File(path); |
|
|
|
// 检查目录是否存在
|
|
|
|
if(fdFile.exists()){ |
|
|
|
try { |
|
|
|
InputStream ins = new FileInputStream(fdFile); |
|
|
|
BufferedReader br = new BufferedReader(new InputStreamReader(ins)); |
|
|
|
String readLine = null; |
|
|
|
StringBuffer sb = new StringBuffer(); |
|
|
|
return sb.toString(); |
|
|
|
}catch (Exception ex){ |
|
|
|
ex.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |