숫자 반올림, 제곱함수
반올림 : Math.round
'Programming > Java / Flex' 카테고리의 다른 글
FIle Copy 방식 (0) | 2015.01.08 |
---|---|
[Flex] Popup창에서 부모창으로 데이터 호출하기 (0) | 2013.11.27 |
[Eclipse] 단축키 (0) | 2013.05.28 |
[Flex] Datagrid / Arraycollection addItem(At) (0) | 2013.05.05 |
PowerJava [2판] Theory Chaper 06 반복문 (0) | 2013.01.29 |
FIle Copy 방식
출처 : http://examples.javacodegeeks.com/core-java/io/file/4-ways-to-copy-file-in-java/
1. Copy File Using FileStreams
This is the most classic way to copy the content of a file to another. You simply read a number of bytes from File A using FileInputStream
and write them to File B using FileOutputStream
.
Here is the code of the first method:
01 | private static void copyFileUsingFileStreams(File source, File dest) |
02 | throws IOException { |
03 | InputStream input = null ; |
04 | OutputStream output = null ; |
05 | try { |
06 | input = new FileInputStream(source); |
07 | output = new FileOutputStream(dest); |
08 | byte [] buf = new byte [ 1024 ]; |
09 | int bytesRead; |
10 | while ((bytesRead = input.read(buf)) > 0 ) { |
11 | output.write(buf, 0 , bytesRead); |
12 | } |
13 | } finally { |
14 | input.close(); |
15 | output.close(); |
16 | } |
17 | } |
As you can see we perform several read and write operations on big chucks of data, so this ought to be a less efficient compared to the next methods we will see.
2. Copy File using java.nio.channels.FileChannel
Java NIO includes a transferFrom
method that according to the documentation is supposed to do faster copying operations than FileStreams.
Here is the code of the second method:
01 | private static void copyFileUsingFileChannels(File source, File dest) |
02 | throws IOException { |
03 | FileChannel inputChannel = null ; |
04 | FileChannel outputChannel = null ; |
05 | try { |
06 | inputChannel = new FileInputStream(source).getChannel(); |
07 | outputChannel = new FileOutputStream(dest).getChannel(); |
08 | outputChannel.transferFrom(inputChannel, 0 , inputChannel.size()); |
09 | } finally { |
10 | inputChannel.close(); |
11 | outputChannel.close(); |
12 | } |
13 | } |
3. Copy File using Apache Commons IO
Apache Commons IO offers a copyFile(File srcFile, File destFile)
method in its FileUtils
class that can be used to copy a file to another. It’s very convenient to work with Apache Commons FileUtils
class when you already using it to your project. Basically, this class uses Java NIO FileChannel
internally.
Here is the code of the third method:
1 | private static void copyFileUsingApacheCommonsIO(File source, File dest) |
2 | throws IOException { |
3 | FileUtils.copyFile(source, dest); |
4 | } |
4. Copy File using Java 7 Files
class
If you have some experience in Java 7 you will probably know that you can use the copy
mehtod of the class Files
in order to copy a file to another.
Here is the code of the fourth method:
1 | private static void copyFileUsingJava7Files(File source, File dest) |
2 | throws IOException { |
3 | Files.copy(source.toPath(), dest.toPath()); |
4 | } |
'Programming > Java / Flex' 카테고리의 다른 글
숫자 반올림, 제곱함수 (0) | 2015.01.08 |
---|---|
[Flex] Popup창에서 부모창으로 데이터 호출하기 (0) | 2013.11.27 |
[Eclipse] 단축키 (0) | 2013.05.28 |
[Flex] Datagrid / Arraycollection addItem(At) (0) | 2013.05.05 |
PowerJava [2판] Theory Chaper 06 반복문 (0) | 2013.01.29 |
Table 권한 주기
주려는 권한 항목을 SELECT, INSERT, DELETE, UPDATE로 선언하고
테이블명 뒤에 주려는 계정명을 입력한다.
'Programming > SQL' 카테고리의 다른 글
CLOB 구문 검색방법 (0) | 2015.02.19 |
---|---|
[Oracle] 숫자관련 함수 (0) | 2013.11.27 |
[SQL] Parametert(변수) 입력시 변수형태 주의점 (spring/mybatis) (0) | 2013.05.05 |
[SQL] Data Type (Char) (0) | 2013.04.12 |
[Oracle] Table Column의 추가 / 변경 / 삭제 (0) | 2013.04.09 |