import java.io.*;
public class BlockingIOExample {
public static void main(String[] args) {
try {
InputStream inputStream = new FileInputStream("input.txt");
OutputStream outputStream = new FileOutputStream("output.txt");
int data;
while ((data = inputStream.read()) != -1) {
outputStream.write(data);
}
inputStream.close();
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
import java.io.*;
import java.nio.*;
public class NonBlockingIOExample {
public static void main(String[] args) {
try {
FileInputStream inputStream = new FileInputStream("input.txt");
FileChannel channel = inputStream.getChannel();
FileOutputStream outputStream = new FileOutputStream("output.txt");
FileChannel channel = outputStream.getChannel();
ByteBuffer buffer = ByteBuffer.allocate(1024);
while (channel.read(buffer) != -1) {
buffer.flip();
while (buffer.hasRemaining()) {
outputChannel.write(buffer);
}
buffer.clear();
}
channel.close();
inputStream.close();
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}