package com.godoro.nio.channel;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
public class FileRead {
public static void main(String[] args) throws Exception{
String path = "input.txt";
RandomAccessFile file = new RandomAccessFile(path, "rw");
FileChannel channel = file.getChannel();
ByteBuffer buffer = ByteBuffer.allocate(64);
System.out.print("Dosyanın içeriği:\r\n");
int actual = channel.read(buffer);
while (actual != -1) {
buffer.flip();
while (buffer.hasRemaining()) {
char character=(char)buffer.get();
System.out.print(character);
}
buffer.clear();
actual = channel.read(buffer);
}
System.out.println();
file.close();
}
}
Dosyayı İndir