동일 서버에 있는 파일 다른 이름으로 복사
File fileCheck = new File("C:\파일");
if (fileCheck.isFile() ) {
//파일이 존재하면
} else {
//존재하지 않으면
}
----------------------------------------------------------------------------------
// 복사 원본 파일
File orgFile = new File("/home/myhome/ff.sh");
// 복사 사본 파일
File newFile = new File("/home/youhome/ff.sh");
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
byte[] buf = new byte[1024 * 2];
int len = -1;
try {
bis = new BufferedInputStream(new FileInputStream(orgFile));
bos = new BufferedOutputStream(new FileOutputStream(newFile));
while((len = bis.read(buf, 0, buf.length)) != -1) {
bos.write(buf, 0, len);
bos.flush();
}
} catch(IOException ioe) {
ioe.printStackTrace();
} finally {
// 파일 자원 해제
if(fos != null) try { fos.close(); } catch(Exception e) {}
if(fis != null) try { fis.close(); } catch(Exception e) {}
}