Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Hans Zhang 1911512
Complier renew
Commits
26809949
Commit
26809949
authored
3 years ago
by
Hans Zhang 1911512
Browse files
Options
Download
Patches
Plain Diff
Upload New File
parent
2db383f1
master
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
sysyruntimelibrary/source/FileUtil.java
+63
-0
sysyruntimelibrary/source/FileUtil.java
with
63 additions
and
0 deletions
+63
-0
sysyruntimelibrary/source/FileUtil.java
0 → 100644
+
63
−
0
View file @
26809949
package
utils
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
import
java.security.MessageDigest
;
import
java.util.ArrayDeque
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Objects
;
import
java.util.Queue
;
/**
* @Author : YML
* @Description:
* @Date created at 2020/5/12 15:21
**/
public
class
FileUtil
{
/**
* 通过广度优先遍历获取一个目录下的所有文件的绝对路径
* @param dictionaryPath 目录的绝对路径
* @return 所有文件的绝对路径
*/
public
static
List
<
String
>
getFilePathByBFS
(
String
dictionaryPath
){
List
<
String
>
ans
=
new
ArrayList
<>();
searchFilePathByBFS
(
dictionaryPath
,
file
->
{
if
(!
file
.
isDirectory
()){
ans
.
add
(
file
.
getAbsolutePath
());
}
return
false
;
});
return
ans
;
}
public
interface
FileFoundCallBack
{
boolean
onFound
(
File
file
);
}
public
static
void
searchFilePathByBFS
(
String
dictionaryPath
,
FileFoundCallBack
callBack
){
Queue
<
String
>
queue
=
new
ArrayDeque
<>();
queue
.
add
(
dictionaryPath
);
boolean
breakFlag
=
false
;
while
(!
breakFlag
&&
!
queue
.
isEmpty
()){
String
currentDicPath
=
queue
.
poll
();
File
currentDic
=
new
File
(
currentDicPath
);
if
(!
currentDic
.
exists
()
||
!
currentDic
.
isDirectory
()
){
continue
;
}
File
[]
files
=
currentDic
.
listFiles
();
assert
files
!=
null
;
for
(
File
file:
files
){
if
(
callBack
.
onFound
(
file
)){
breakFlag
=
true
;
break
;
}
if
(
file
.
isDirectory
()){
queue
.
add
(
file
.
getAbsolutePath
());
}
}
}
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Topics
Snippets