On 2019-08-26 15:13, Mgr. Janusz Chmiel wrote:
Please, does somebody of us know how to write file by using binary
mode and writing data from The variable which have JNByteBuffer
variable type?

Here is a Java example on how to do it. You need to use java.io.FileOutputStream (JIFileOutputStream in FPC):

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class Main {
  public static void main(String[] args) throws Exception {
    String fromFileName = "from.txt";
    String toFileName = "to.txt";
    FileChannel in = new FileInputStream(fromFileName).getChannel();
    FileChannel out = new FileOutputStream(toFileName).getChannel();

    ByteBuffer buff = ByteBuffer.allocateDirect(32 * 1024);

    while (in.read(buff) > 0) {
      buff.flip();
      out.write(buff);
      buff.clear();
    }

    in.close();
    out.close();
  }
}

(reproduced from http://www.java2s.com/Code/Java/File-Input-Output/WritewithByteBuffer.htm )


Jonas
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to