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 :
- Este artículo puede utilizar software de traducción para su comodidad. Consulte también la versión original en inglés.
Summary
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 ()
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 ()
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
- Ejemplos de API