-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIoDemo.java
More file actions
65 lines (58 loc) · 1.5 KB
/
IoDemo.java
File metadata and controls
65 lines (58 loc) · 1.5 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package webproject.thinkinjava;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class IoDemo {
public static void main(String[] args) throws IOException, InterruptedException {
File src = new File("e:/test/li/超高清晰世界地图.jpg");
File dest = new File("e:/test/li/超高清晰世界地图copy.jpg");
fileCopy(src,dest);
// fileTemp();
}
/**
* 字节流33
* 字节流22
* @param src
* @param dest
* @throws IOException
*/
public static void fileCopy(File src, File dest) throws IOException{
if(!dest.exists()){
dest.getParentFile().mkdirs();
dest.createNewFile();
}
InputStream fis = new BufferedInputStream(new FileInputStream(src));
OutputStream fos = new BufferedOutputStream(new FileOutputStream(dest));
byte[] flush = new byte[1024];
int len = 0;
while(-1 != (len = fis.read(flush))){
fos.write(flush, 0, 11);
}
fis.close();
fos.close();
}
/**
* 临时文件
* @throws IOException
* @throws InterruptedException
*/
public static void fileTemp() throws IOException, InterruptedException{
for(int i = 0; i < 10; i ++){
File src = File.createTempFile("lll", "eeee", new File("e:/test/li"));
Thread.sleep(2000);
src.delete();
// src.deleteOnExit();
}
}
/**
*
*/
public static void charCopy(){
File src = new File("");
}
}