-
Notifications
You must be signed in to change notification settings - Fork 0
/
FilesUtil
41 lines (33 loc) · 1.1 KB
/
FilesUtil
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 org.exec.util;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class FilesUtil {
public static void saveFile(File file, String fileName, String filesDirectory) throws IOException{
FileInputStream in = null;
FileOutputStream out = null;
File dir = new File (filesDirectory);
if ( !dir.exists() )
dir.mkdirs();
String targetPath = dir.getPath() + File.separator + fileName;
System.out.println("source file path ::"+file.getAbsolutePath());
System.out.println("saving file to ::" + targetPath);
File destinationFile = new File ( targetPath);
try {
in = new FileInputStream( file );
out = new FileOutputStream( destinationFile );
int c;
while ((c = in.read()) != -1) {
out.write(c);
}
}finally {
if (in != null) {
in.close();
}
if (out != null) {
out.close();
}
}
}
}