Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
YZG
yzg-util
Commits
17269ffa
Commit
17269ffa
authored
Jun 01, 2020
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
压缩视频
parent
e4eae311
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
12 deletions
+37
-12
FileHelper.java
...src/main/java/com/yanzuoguang/util/helper/FileHelper.java
+32
-11
LogDefault.java
...se/src/main/java/com/yanzuoguang/util/log/LogDefault.java
+1
-1
TestByteHelper.java
yzg-util-base/src/test/java/log/TestByteHelper.java
+4
-0
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/helper/FileHelper.java
View file @
17269ffa
...
...
@@ -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
writeFile
Append
(
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
);
}
}
/**
* 根据路径删除指定的目录或文件,无论存在与否
*
...
...
yzg-util-base/src/main/java/com/yanzuoguang/util/log/LogDefault.java
View file @
17269ffa
...
...
@@ -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
.
writeFile
Append
(
new
File
(
path
),
sb
.
toString
(),
"UTF-8"
);
}
}
}
yzg-util-base/src/test/java/log/TestByteHelper.java
View file @
17269ffa
...
...
@@ -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秒秒"
);
}
});
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment