package com.godoro.nio.buffer;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.GatheringByteChannel;
public class FileGather {
public static void main(String[] args) throws Exception {
String path = "gatherscatter.txt";
int number=1234;
String text = "Godoro Java Database";
ByteBuffer buffer1 = ByteBuffer.allocate(1024);
buffer1.asIntBuffer().put(number);
ByteBuffer buffer2 = ByteBuffer.allocate(1024);
buffer2.asCharBuffer().put(text);
FileOutputStream out = new FileOutputStream(path);
GatheringByteChannel gathering = out.getChannel();
gathering.write(new ByteBuffer[]{buffer1, buffer2});
out.close();
gathering.close();
}
}
Dosyayı İndir