KickJava   Java API By Example, From Geeks To Geeks.

Java > Java SE, EE, ME > java > nio > MappedByteBuffer

java.nio
Class MappedByteBuffer

java.lang.Object
  extended by java.nio.Buffer
      extended by java.nio.ByteBuffer
          extended by java.nio.MappedByteBuffer
All Implemented Interfaces:
Comparable<ByteBuffer>
See Also:
Top Examples, Source Code, FileChannel.map

public final MappedByteBuffer force()
See Also:
FileChannel.MapMode.READ_WRITE
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public final boolean isLoaded()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public final MappedByteBuffer load()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1084]Decode a file based on specific Charset
By Anonymous on 2004/10/29 23:56:56  Rate
public class ReadFileBuff  {  
   public static void main ( String args [  ]  )  throws IOException  {  
      if  ( args.length != 0 )   {  
       String filename = args [ 0 ] ; 
       FileInputStream fis = new FileInputStream ( filename ) ; 
       FileChannel channel = fis.getChannel (  ) ; 
       int length =  ( int ) channel.size (  ) ; 
       MappedByteBuffer byteBuffer = 
         channel.map ( FileChannel.MapMode.READ_ONLY, 0, length ) ; 
       Charset charset = Charset.forName ( "ISO-8859-1" ) ; 
       CharsetDecoder decoder = charset.newDecoder (  ) ; 
       CharBuffer charBuffer = decoder.decode ( byteBuffer ) ; 
       for  ( int i=0, n=charBuffer.length (  ) ; i < n; i++ )   {  
         System.out.print ( charBuffer.get (  )  ) ; 
        }  
      }  
    }  
  }  
 

Popular Tags