<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    New I/O

    Channel & ByteBuffer
     channal & buffer - ByteBuffer
    package think.in.java.io;
    /**
     * That are closer to the operating system’s way of performing I/O: channels and buffers.
     * The only kind of buffer that communicates directly with a channel is a ByteBuffer—that is, 
     * a buffer that holds raw bytes.
     * 
     * It’s fairly low-level, precisely because this makes a more efficient mapping with most operating systems.
     * 
     * Here’s a simple example that exercises all three types of stream 
     * to produce channels that are writeable, read/writeable, and readable:
     * 
    @author WPeng
     *
     * 
    @since 2012-11-6
     
    */
    public class GetChannel {

        
    private static final int BSIZE = 1024;

        
    public static void main(String[] args) throws Exception {
            
    // Write a file
            FileChannel fc = new FileOutputStream("data.txt").getChannel();
            fc.write(ByteBuffer.wrap(
    "Some text".getBytes()));
            fc.close();
            
            
    // Add to the end of the file
            fc = new RandomAccessFile("data.txt""rw").getChannel();
            fc.position(fc.size());  
    //move to the end
            fc.write(ByteBuffer.wrap("Some more".getBytes()));
            fc.close();
            
            
    // Read the file
            fc = new FileInputStream("data.txt").getChannel();
            ByteBuffer buff 
    = ByteBuffer.allocate(BSIZE);
            
    /**
                Reads a sequence of bytes from this channel into the given buffer.
                Bytes are read starting at this channel's current file position,
                and then the file position is updated with the number of bytes actually read.

                -1 if the channel has reached end-of-stream
            
    */
            fc.read(buff);
            buff.flip();
            
    while(buff.hasRemaining()){
                System.out.print((
    char)buff.get());
            }
        }

    }
    transferTo & transferFrom
    package think.in.java.io;
    /**
     * Using transferTo() between channels 
     * {Args: TransferTo.java TransferTo.txt}
     * 
    @author WPeng
     *
     * 
    @since 2012-11-6
     
    */
    public class TransferTo {
        
    public static void main(String[] args) throws IOException{
            
    if(args.length != 2){
                System.out.println(
    "arguments: sourcefile destfile");
                System.exit(
    1);
            }
            FileChannel in 
    = new FileInputStream(args[0]).getChannel(),
                        out 
    = new FileOutputStream(args[1]).getChannel();
            in.transferTo(
    0, in.size(), out);
            
    // or:
            
    // out.transferFrom(in, 0, in.size());
        }
    }









    posted on 2012-11-06 14:42 鹽城小土包 閱讀(120) 評論(0)  編輯  收藏 所屬分類: J2EE

    <2025年5月>
    27282930123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

    導航

    統計

    常用鏈接

    留言簿

    隨筆檔案(14)

    文章分類(18)

    文章檔案(18)

    搜索

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 亚洲中文字幕久在线| 中文字幕亚洲天堂| 亚洲人成网站18禁止久久影院| a色毛片免费视频| 成人午夜亚洲精品无码网站| 国产在线观看免费完整版中文版 | 亚洲短视频在线观看| 香蕉免费一区二区三区| 亚洲成人在线电影| 131美女爱做免费毛片| 亚洲第一网站免费视频| 2022久久国产精品免费热麻豆| 亚洲天堂中文资源| 在线视频精品免费| 亚洲狠狠成人综合网| 日本无吗免费一二区| 国产区图片区小说区亚洲区| 亚洲国产av一区二区三区| 一级成人毛片免费观看| 亚洲av无码一区二区三区不卡| 免费在线中文日本| 亚洲免费人成视频观看| 精品国产麻豆免费网站| 激情吃奶吻胸免费视频xxxx| 中文字幕亚洲专区| 51在线视频免费观看视频| 亚洲熟妇自偷自拍另欧美| 亚洲?V无码乱码国产精品| 最近中文字幕免费大全| 亚洲人成网站日本片| 免费人成年轻人电影| 日韩免费电影网址| 亚洲日本在线电影| 亚洲熟妇无码八AV在线播放| 99爱在线观看免费完整版| 亚洲一区二区三区在线观看网站| 日产国产精品亚洲系列| 日韩精品极品视频在线观看免费| 亚洲爆乳无码专区www| 国产亚洲无线码一区二区| 皇色在线视频免费网站|