'修改界面样式风格'

This commit is contained in:
2019-03-29 16:56:27 +08:00
parent 3df7e52e61
commit fe9afaa584
4 changed files with 180 additions and 6 deletions

View File

@@ -0,0 +1,151 @@
package net.tccn.base;
import java.io.*;
import java.net.URL;
import java.net.URLDecoder;
import java.nio.file.Files;
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
import static java.util.Arrays.asList;
/**
* Created by liangxianyou at 2018/5/31 10:23.
*/
public final class FileKit {
private FileKit() { }
public static void strToFile(String entityBody, File file) throws IOException {
strToFile(entityBody, file, true);
}
public static void strToFile(String entityBody, File file, boolean existDel) throws IOException {
if (file.exists()) {
if (existDel) {
file.delete();
}else {
throw new RuntimeException(file.getPath() + "已经存在");
}
}
if (!file.getParentFile().exists()){
file.getParentFile().mkdirs();
}
FileOutputStream out = new FileOutputStream(file);
out.write(entityBody.getBytes("UTF-8"));
out.close();
}
/**
* 拷贝文件/文件目录
* @param source
* @param target
* @param linkPath
*/
public static void copyFiles(File source, File target, String linkPath) {
if (source.isDirectory()){
final String _linkPath = linkPath + File.separator+ source.getName();
asList(source.listFiles()).forEach(f->{
copyFiles(f, target, _linkPath);
});
}else if (source.isFile()){
try {
String _linkPath = "";
int index = linkPath.indexOf(File.separator, 1);
if (index > 0){
_linkPath = linkPath.substring(index);
}
File targetFile = new File(target.toPath() + _linkPath + File.separator + source.getName());
if (!targetFile.getParentFile().exists()){
targetFile.getParentFile().mkdirs();
}
Files.copy(source.toPath(), targetFile.toPath(), REPLACE_EXISTING);
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* 获取 clazz的路径如果是jar里面的文件得到jar存放的目录lib
* @param clazz
* @return
*/
public static String rootPath(Class clazz){
//return clazz.getClassLoader().getResource("").getPath();
URL url = clazz.getProtectionDomain().getCodeSource().getLocation();
try {
String filePath = URLDecoder.decode(url.getPath(), "utf-8");
if (filePath.endsWith(".jar")){
return filePath.substring(0, filePath.lastIndexOf("/")+1);
}
return filePath;
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return "";
}
/**
* 读取流内的所有内容
* @param inputStream
* @return
* @throws IOException
*/
public static String readAll(InputStream inputStream) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
StringBuffer buf = new StringBuffer();
String str;
while ((str = reader.readLine()) != null){
buf.append(str+ "\n");
}
return buf.toString();
}
/**
* 渲染模板到文件
* @param sourceStr
* @param target
* @param kv
*/
/*public static void tplRender(String sourceStr, File target, Kv kv){
String str = "";
if (sourceStr != null && !sourceStr.isEmpty()){
str = Engine.use().getTemplateByString(sourceStr).renderToString(kv);
}
try {
strToFile(str, target, true);
} catch (IOException e) {
e.printStackTrace();
}
}*/
/**
* 通过模板创建内容
* @param tplFile
* @param para
*/
/*public static void tplRender(File tplFile, File file, Map para) throws IOException {
String str = Engine.use().getTemplate(tplFile.getPath()).renderToString(para);
strToFile(str, file);
}*/
/*public static String tplRender(File tplFile, Map para){
return Engine.use().getTemplate(tplFile.getPath()).renderToString(para);
}*/
/*public static void objToFile(Object obj, File file) throws FileNotFoundException {
if (file.exists()) {
throw new RuntimeException(file.getPath() + "已经存在");
}
if (!file.getParentFile().exists()){
file.getParentFile().mkdirs();
}
FileOutputStream out = new FileOutputStream(file);
out.write(obj.);
out.close();
}*/
}