1. 파일패스 컬럼에 내용이 있는 경우는 written time 위에
파일명 : [파일명] 이와 같이 나온다.
2. apache commons 사용
3. 한글 파일명 지원 안함. 그냥 다운 받을때 정해도 되는 문제라;
4. board의 id값을 getMessage로 넘김.
5. 파일이 다운로드 되고 돌아오는 페이지는 우선 첫번째 페이지
전체화면후, 파일다운로드후 돌아오는 페이지에 관한 것은 추후 기능 추가.
1. 파일패스 컬럼에 내용이 있는 경우는 written time 위에
파일명 : [파일명] 이와 같이 나온다.
2. apache commons 사용
3. 한글 파일명 지원 안함. 그냥 다운 받을때 정해도 되는 문제라;
4. board의 id값을 getMessage로 넘김.
5. 파일이 다운로드 되고 돌아오는 페이지는 우선 첫번째 페이지
전체화면후, 파일다운로드후 돌아오는 페이지에 관한 것은 추후 기능 추가.
import java.io.*;
public class CopyFileIOversion{
private static void copyfile(String srFile, String dtFile){
try{
File f1 = new File(srFile);
File f2 = new File(dtFile);
InputStream in = new FileInputStream(f1);
//For Overwrite the file.
OutputStream out = new FileOutputStream(f2);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0){
out.write(buf, 0, len);
}
in.close();
out.close();
System.out.println("File copied.");
}
catch(FileNotFoundException ex){
System.out.println(ex.getMessage() + " in the specified directory.");
System.exit(0);
}
catch(IOException e){
System.out.println(e.getMessage());
}
}
public static void main(String[] args){
long start=System.currentTimeMillis();
copyfile("D:/Downloads/totodisk/BestProf/080324.avi","c:/bbd.avi");
System.out.println((System.currentTimeMillis() - start)/1000);
}
}
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
public class CopyFileNIOversion {
public static void main(String args[]) {
long start=System.currentTimeMillis();
FileInputStream fIn;
FileOutputStream fOut;
FileChannel fIChan, fOChan;
long fSize;
MappedByteBuffer mBuf;
try {
fIn = new FileInputStream("D:/Downloads/totodisk/BestProf/080325.avi");
fOut = new FileOutputStream("c:/aaasdf.avi");
fIChan = fIn.getChannel();
fOChan = fOut.getChannel();
fSize = fIChan.size();
mBuf = fIChan.map(FileChannel.MapMode.READ_ONLY, 0, fSize);
fOChan.write(mBuf); // this copies the file
fIChan.close();
fIn.close();
fOChan.close();
fOut.close();
} catch (IOException exc) {
System.out.println(exc);
System.exit(1);
} catch (ArrayIndexOutOfBoundsException exc) {
System.out.println("Usage: Copy from to");
System.exit(1);
}
System.out.println((System.currentTimeMillis()-start)/1000);
}
}
3배가 난다고 했는데 아닌것 같다.
채널을 이용하고 자세한건 예전에 읽어 기억이 안나는데
io는 stream으로 nio는 block으로 읽는 다고만 어렴풋이; 방금 본부분만 기억이난다.
속도는 nio가 더 빠르다. 하지만 윈도우에서 파일 복사 하는게 제일 빠르다.
그냥 윈도우가 제일 빠른듯 ㅋ
700메가를 하드에서 다른 곳에 카피하는데 걸리는 시간이
nio는 34초
io는 57초
윈도우 7으로 하면 20초 남짓? ㅋㅋ