Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
29 lines (23 loc) · 892 Bytes

File metadata and controls

29 lines (23 loc) · 892 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
package com.example.newio;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
/**
* Created by riven_chris on 15/8/6.
*/
public class ChannelCopy {
private static final int SIZE = 1024;
public static void main(String[] args) throws IOException {
FileChannel in = new FileInputStream("test_files/data.txt").getChannel(),
out = new FileOutputStream("test_files/data2.txt").getChannel();
ByteBuffer buffer = ByteBuffer.allocate(SIZE);
//本例中并不是处理此类操作的最理想方式。使用特殊方法transferTo()和transferFrom()。
while (in.read(buffer) != -1) {
buffer.flip();//Prepare for writing
out.write(buffer);
buffer.clear();//Prepare for reading
}
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.