import java.io.*;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
public class ExplicitChannelRead {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
FileInputStream fIn = null;
FileChannel fChan = null;
ByteBuffer mBuf;
int count;
try{
fIn = new FileInputStream("text.txt");
fChan = fIn.getChannel();
mBuf = ByteBuffer.allocate(128);
do{
count = fChan.read(mBuf);
if(count!=-1){
mBuf.rewind();
for(int i =0; i<count; i++)
System.out.print((char) mBuf.get());
}
}while(count!=-1);
System.out.println();
}catch(IOException e){
System.out.println("I/O Error : " + e);
}finally{
try{
if(fChan!=null)
fChan.close();
}catch(IOException e){
System.out.println("Error closing Channel.");
}
try{
if(fIn!= null)
fIn.close();
}catch(IOException e){
System.out.println("Error closing file.");
}
}
}
}
当我在命令提示符下编译此代码时,出现错误
ExplictChannelRead.java:58:error:class, interface, or enum expected }
当我在我的 IDE 中编译它时,我收到以下错误
"Exception in thread "main" java.lang.Error: Unresolved compilation problem:
at nio_path.ExplicitChannelRead.main(ExplicitChannelRead.java:12)"
我从书中复制了整个代码。