Java : Channel con ejemplos

Channel (Java SE 22 & JDK 22) en Java con ejemplos.
Encontrará muestras de código para la mayoría de los métodos Channel.

Nota :


Summary

Un nexo para operaciones de E/S. (Traducción automática)

Class diagram

final var path = Path.of("R:", "java-work", "test.data");
System.out.println(path); // R:\java-work\test.data

Channel channel;
try (final var fc = FileChannel.open(path,
        StandardOpenOption.CREATE, StandardOpenOption.WRITE)) {

    channel = fc;
    System.out.println(channel.isOpen()); // true
}

System.out.println(channel.isOpen()); // false

Methods

void close ()

Cierra este canal. (Traducción automática)

final var path = Path.of("R:", "java-work", "test.data");
System.out.println(path); // R:\java-work\test.data

Channel channel;
try (final var fc = FileChannel.open(path,
        StandardOpenOption.CREATE, StandardOpenOption.WRITE)) {

    channel = fc;
    System.out.println(channel.isOpen()); // true
}

System.out.println(channel.isOpen()); // false
// An example without a try-with-resources statement.
final var path = Path.of("R:", "java-work", "test.data");
System.out.println(path); // R:\java-work\test.data

final Channel channel = FileChannel.open(path,
        StandardOpenOption.CREATE, StandardOpenOption.WRITE);
try {
    System.out.println(channel.isOpen()); // true
} finally {
    channel.close();
}

System.out.println(channel.isOpen()); // false

boolean isOpen ()

Indica si este canal está abierto o no. (Traducción automática)

final var path = Path.of("R:", "java-work", "test.data");
System.out.println(path); // R:\java-work\test.data

Channel channel;
try (final var fc = FileChannel.open(path,
        StandardOpenOption.CREATE, StandardOpenOption.WRITE)) {

    channel = fc;
    System.out.println(channel.isOpen()); // true
}

System.out.println(channel.isOpen()); // false
// An example without a try-with-resources statement.
final var path = Path.of("R:", "java-work", "test.data");
System.out.println(path); // R:\java-work\test.data

final Channel channel = FileChannel.open(path,
        StandardOpenOption.CREATE, StandardOpenOption.WRITE);
try {
    System.out.println(channel.isOpen()); // true
} finally {
    channel.close();
}

System.out.println(channel.isOpen()); // false

Related posts

To top of page