<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 鹽城小土包 閱讀(119) 評論(0)  編輯  收藏 所屬分類: J2EE

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

    導航

    統(tǒng)計

    常用鏈接

    留言簿

    隨筆檔案(14)

    文章分類(18)

    文章檔案(18)

    搜索

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: A级毛片高清免费视频在线播放| 四虎精品视频在线永久免费观看 | 亚洲人成人无码网www电影首页 | 最近中文字幕无免费| 亚洲影院天堂中文av色| 亚洲日韩在线中文字幕第一页| 99re这里有免费视频精品| 亚洲日本VA中文字幕久久道具| 亚洲中文字幕无码爆乳av中文 | 一个人免费高清在线观看| 免费人成在线观看播放a| 亚洲综合视频在线| 四虎影在线永久免费观看| 久久国产色AV免费观看| www亚洲精品久久久乳| 亚洲精品视频在线免费| 久久久久国产亚洲AV麻豆| 最近最新MV在线观看免费高清| 韩国免费A级毛片久久| 亚洲第一区二区快射影院| 久久亚洲高清观看| 国产福利免费观看| 在线看免费观看AV深夜影院| 一个人看的免费观看日本视频www| 国产精品亚洲午夜一区二区三区| 亚洲热妇无码AV在线播放| 国产在线98福利播放视频免费| 中文免费观看视频网站| 久久久久久国产a免费观看不卡| 亚洲AV无码一区二区三区久久精品 | 无码一区二区三区AV免费| 在线观看黄片免费入口不卡| 亚洲av无码专区在线观看下载 | 亚洲Av无码专区国产乱码DVD| 亚洲?V乱码久久精品蜜桃| 国拍在线精品视频免费观看| 久久久久久久久久国产精品免费| 色多多A级毛片免费看| 亚洲AV日韩综合一区| 亚洲av片不卡无码久久| 亚洲精品一区二区三区四区乱码|