Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
leaf-hlcm
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
hlcm
leaf-hlcm
Commits
1120071d
Commit
1120071d
authored
Jan 16, 2023
by
gzj34291
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
文件下载
parent
b713c20e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
79 additions
and
0 deletions
+79
-0
DoloadFileByUrl.java
src/main/java/com/hand/hl/DoloadFileByUrl.java
+79
-0
No files found.
src/main/java/com/hand/hl/DoloadFileByUrl.java
0 → 100644
View file @
1120071d
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//
package
com
.
hand
.
hl
;
import
java.io.BufferedInputStream
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
java.net.HttpURLConnection
;
import
java.net.MalformedURLException
;
import
java.net.URL
;
import
java.net.URLConnection
;
public
class
DoloadFileByUrl
{
public
DoloadFileByUrl
()
{
}
public
static
void
main
(
String
[]
args
)
{}
public
static
Boolean
downloadFile
(
String
urlPath
,
String
downloadDir
,
String
fileName
)
{
File
file
=
null
;
BufferedInputStream
bin
=
null
;
OutputStream
out
=
null
;
Boolean
flag
=
true
;
try
{
String
path
=
downloadDir
+
File
.
separatorChar
+
fileName
;
int
len
=
0
;
byte
[]
buf
=
new
byte
[
1024
];
int
size
;
URL
url
=
new
URL
(
urlPath
);
URLConnection
urlConnection
=
url
.
openConnection
();
HttpURLConnection
httpURLConnection
=
(
HttpURLConnection
)
urlConnection
;
httpURLConnection
.
setRequestMethod
(
"GET"
);
httpURLConnection
.
setRequestProperty
(
"Charset"
,
"UTF-8"
);
httpURLConnection
.
connect
();
int
fileLength
=
httpURLConnection
.
getContentLength
();
URLConnection
con
=
url
.
openConnection
();
bin
=
new
BufferedInputStream
(
httpURLConnection
.
getInputStream
());
file
=
new
File
(
path
);
if
(!
file
.
getParentFile
().
exists
())
{
file
.
getParentFile
().
mkdirs
();
}
out
=
new
FileOutputStream
(
file
);
while
((
size
=
bin
.
read
(
buf
))
!=
-
1
)
{
len
+=
size
;
out
.
write
(
buf
,
0
,
size
);
}
}
catch
(
MalformedURLException
var15
)
{
var15
.
printStackTrace
();
flag
=
false
;
}
catch
(
IOException
var16
)
{
var16
.
printStackTrace
();
flag
=
false
;
}
finally
{
try
{
if
(
bin
!=
null
)
{
bin
.
close
();
}
if
(
out
!=
null
)
{
out
.
close
();
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
flag
=
false
;
}
}
return
flag
;
}
}
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