随笔-153  评论-235  文章-19  trackbacks-0

 



import  java.io.File;
import  java.io.FileInputStream;
import  java.io.FileNotFoundException;
import  java.io.IOException;
import  java.nio.ByteBuffer;
import  java.nio.channels.FileChannel;


public   class  ReadAString  {

    
/**
     * 
@param  args
     
*/

    
public   static   void  main(String[] args)  {
        
//  TODO 自动生成方法存根

        File aFile 
=   new  File( " d:/test.txt " );
        FileInputStream inFile 
=   null ;
        
        
try   {
            inFile 
=   new  FileInputStream(aFile);
        }
  catch (FileNotFoundException e)  {
            e.printStackTrace(System.err);
            System.exit(
1 );
        }

        
        FileChannel inChannel 
=  inFile.getChannel();
        ByteBuffer buf 
=  ByteBuffer.allocate( 48 );
        
// String buf = "";
         try   {
            
while (inChannel.read(buf)  !=   - 1 {
                System.out.println(
" String read:  " +
                        ((ByteBuffer)(buf.flip())).asCharBuffer().toString());
                buf.clear();
            }

            System.out.println(
" EOF readched. " );
            inFile.close();
        }
  catch (IOException e)  {
            e.printStackTrace(System.err);
            System.exit(
1 );
        }

        
        System.exit(
0 );
    }


}

posted on 2006-11-11 15:40 流浪汗 阅读(362) 评论(0)  编辑  收藏 所属分类: Java

只有注册用户登录后才能发表评论。


网站导航: