Skip to content

Commit 0d7bf48

Browse files
committed
detail improve
1 parent 30e852d commit 0d7bf48

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# doujin_reference
2-
Set JAVA 1st parameter as web url.
2+
Set config file before running.

conf/urlList.txt

Whitespace-only changes.

src/main/java/phantancy/doujin/io/file/DownloadPic.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,17 @@ public class DownloadPic {
1818

1919
private static final boolean overrideFile = false;
2020

21-
// TODO 下载失败删除当前文件
21+
// TODO remove current file while download fail
2222
public void downloadPicByUrlList(List<String> picUrlList, String folderName) {
2323
log.writeLog("Get " + picUrlList.size() + " image urls.\n Download Start...");
2424
String rootPath = Setting.localSavePath;
25-
File folder = new File(rootPath + "\\" + getEnableFolderName(folderName));
25+
String folderPath;
26+
if (rootPath.isEmpty()) {
27+
folderPath = getEnableFolderName(folderName);
28+
} else {
29+
folderPath = rootPath + "\\" + getEnableFolderName(folderName);
30+
}
31+
File folder = new File(folderPath);
2632
if (!folder.exists() || !folder.isDirectory()) {
2733
folder.mkdir();
2834
}
@@ -58,22 +64,18 @@ public void downloadPicByUrlList(List<String> picUrlList, String folderName) {
5864
InputStream is = null;
5965
OutputStream os = null;
6066
try {
61-
// 构造URL
6267
URL url = new URL(imageUrl);
63-
// 打开连接
6468
URLConnection con = url.openConnection();
65-
// 设置请求超时为5s
69+
// Timeout 5 seconds
6670
con.setConnectTimeout(5000);
67-
// 输入流
6871
is = con.getInputStream();
6972

70-
// 1K的数据缓冲
73+
// 1K buffer
7174
byte[] bs = new byte[1024];
72-
// 读取到的数据长度
75+
// read length
7376
int len;
74-
// 输出的文件流
7577
os = new FileOutputStream(imageFile);
76-
// 开始读取
78+
// start reading
7779
while ((len = is.read(bs)) != -1) {
7880
os.write(bs, 0, len);
7981
}

0 commit comments

Comments
 (0)