Commit 17269ffa authored by yanzg's avatar yanzg

压缩视频

parent e4eae311
......@@ -107,6 +107,7 @@ public class FileHelper {
return sb.toString();
}
/**
* 写入文件内容
*
......@@ -114,17 +115,8 @@ public class FileHelper {
* @param content 文件内容
* @param encoding 文件编码
*/
public static void writeFile(File file, String content, String encoding) {
public static void writeFileAppend(File file, String content, String encoding) {
try {
// 删除文件
if (file.exists()) {
if (!file.delete()) {
throw new CodeException("文件删除失败");
}
}
if (file.exists()) {
throw new CodeException("文件删除失败");
}
// 创建文件夹
File parentFile = file.getParentFile();
if (parentFile != null) {
......@@ -137,7 +129,10 @@ public class FileHelper {
throw new CodeException("创建文件夹失败");
}
}
file.createNewFile();
// 文件不存在则创建
if (!file.exists()) {
file.createNewFile();
}
// 写入文件
RandomAccessFile raf = new RandomAccessFile(file, "rwd");
raf.seek(file.length());
......@@ -150,6 +145,32 @@ public class FileHelper {
}
}
/**
* 写入文件内容
*
* @param file 文件路径
* @param content 文件内容
* @param encoding 文件编码
*/
public static void writeFile(File file, String content, String encoding) {
try {
// 删除文件
if (file.exists()) {
if (!file.delete()) {
throw new CodeException("文件删除失败");
}
}
if (file.exists()) {
throw new CodeException("文件删除失败");
}
writeFileAppend(file, content, encoding);
} catch (CodeException e) {
throw e;
} catch (Exception e) {
throw new CodeException(e);
}
}
/**
* 根据路径删除指定的目录或文件,无论存在与否
*
......
......@@ -77,7 +77,7 @@ public class LogDefault implements RunnableLog {
row.put("day", DateHelper.getToday(info.getNow()));
row.put("thread", info.getThreadId());
String path = StringHelper.getCodeString(pathFormat, row);
FileHelper.writeFile(new File(path), sb.toString(), "UTF-8");
FileHelper.writeFileAppend(new File(path), sb.toString(), "UTF-8");
}
}
}
......@@ -12,12 +12,16 @@ public class TestByteHelper {
RunnableListAuto.run(new Runnable() {
@Override
public void run() {
Log.info(TestByteHelper.class, "等待1秒秒");
Log.info(TestByteHelper.class, "等待2秒秒");
Log.info(TestByteHelper.class, "等待3秒秒");
}
}, new Runnable() {
@Override
public void run() {
Log.info(TestByteHelper.class, "等待1秒秒");
Log.info(TestByteHelper.class, "等待2秒秒");
Log.info(TestByteHelper.class, "等待3秒秒");
}
});
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment