FileInputStream class getChannel () método : Aquí, vamos a aprender sobre el método getChannel () de FileInputStream Class con su sintaxis y su ejemplo.
FileInputStream Class getChannel () método
- método
- getChannel () está disponible en java.io Class.
- getChannel () método se utiliza para class el objeto FileChannel distinta vinculada con este FileInputStream.
- getChannel () método es un método no package, es accesible sólo con el objeto return y si tratamos de acceder al método con el nombre static entonces obtendrá un error.
- método getChannel () no class una excepción a la hora de conseguir canal.
Sintaxis:
public FileChannel getChannel();
Parámetro (s):
- No acepta cualquier parámetro.
class valor:
El tipo throw del método es FileChannel , devuelve el FileChannel conectado con esta corriente.
Ejemplo:
// Java program to demonstrate the example
// of FileChannel getChannel() method
// of FileInputStream
import java.io.*;
import java.nio.channels.*;
public class GetChannelOfFIS {
public static void main(String[] args) throws Exception {
FileInputStream fis_stm = null;
FileChannel file_ch = null;
int count = 0;
try {
// Instantiates FileInputStream
fis_stm = new FileInputStream("C:includehelp.txt");
while ((count = fis_stm.read()) != -1) {
// By using read() method is to read
// a byte from fis_stm
count = fis_stm.read();
// Display corresponding bytes value
byte b = (byte) count;
// Display value of b
System.out.println("fis_stm.read(): " + b);
}
// By using getChannel() method is to return
// FileChannel linked with the stream
file_ch = fis_stm.getChannel();
System.out.println("fis_stm.getChannel(): " + file_ch);
} catch (Exception ex) {
System.out.println(ex.toString());
} finally {
// with the help of this block is to
// free all necessary resources linked
// with the stream
if (fis_stm != null) {
fis_stm.close();
if (file_ch != null) {
file_ch.close();
}
}
}
}
}
salida
fis_stm.read(): 4
fis_stm.read(): 97
fis_stm.read(): 97
fis_stm.read(): 8
fis_stm.read(): 111
fis_stm.read(): 108
fis_stm.read(): 33
fis_stm.read(): 33
fis_stm.getChannel(): [email protected]