-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
41 lines (31 loc) · 1.2 KB
/
Main.java
File metadata and controls
41 lines (31 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package com.cat.multi.copy;
import java.io.File;
import java.io.IOException;
/**
* Created by cat on 2018/1/20.
* 多线程拷贝
*/
public class Main {
public static void main(String[] args) throws IOException, InterruptedException {
String path = Class.class.getClass().getResource("/").getPath();
String rootPath = new File(path).getParentFile().getParentFile().getParentFile().getPath();
File sf = new File(rootPath, "raw/src/memo_methine.pdf"); // src
File df = new File(rootPath, "raw/dest/memo_methine_copied.pdf"); // dest
if (df.isFile()) {
df.delete();
}
long srcsize = sf.length();
System.out.println("srcSize==" + srcsize);
// long pos = 0;
// long end = srcsize / 2 / 1024 * 1024;
long pos1 = 0;
long end1= srcsize / 2 / 1024 * 1024;
Copy copy1 = new Copy(sf.getAbsolutePath(), df.getAbsolutePath(), pos1, end1);
long pos2 = srcsize / 2 / 1024 * 1024;
long end2 = srcsize;
Copy copy2 = new Copy(sf.getAbsolutePath(), df.getAbsolutePath(), pos2, end2);
new Thread(copy2).start();
// Thread.sleep(10);
new Thread(copy1).start();
}
}