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

    <2025年7月>
    293012345
    6789101112
    13141516171819
    20212223242526
    272829303112
    3456789

    導(dǎo)航

    統(tǒng)計(jì)

    常用鏈接

    留言簿

    隨筆檔案(14)

    文章分類(18)

    文章檔案(18)

    搜索

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 成人无码视频97免费| 亚洲色大成网站www久久九| 成人午夜免费视频| 国产大片91精品免费观看男同| 亚洲最大成人网色香蕉| 最近的中文字幕大全免费版| 中文文字幕文字幕亚洲色| 成人毛片免费观看视频大全| 亚洲男人天堂2022| 国产免费直播在线观看视频| 四虎一区二区成人免费影院网址| 亚洲国产日韩在线观频| 国产在线精品一区免费香蕉| 国产精品亚洲片在线| 久久一本岛在免费线观看2020| 久久噜噜噜久久亚洲va久| 日本黄网站动漫视频免费| 亚洲欧美成人一区二区三区| 免费国产成人高清视频网站| 国产精品免费αv视频| 亚洲av丰满熟妇在线播放| **一级毛片免费完整视| 亚洲日本一线产区和二线| 亚洲av无码专区在线观看素人| 香蕉免费看一区二区三区| 亚洲视频一区网站| 又大又硬又爽免费视频| 两个人看的www免费| 亚洲人成人77777在线播放| 狼友av永久网站免费观看| 中国毛片免费观看| 亚洲午夜精品一区二区公牛电影院 | 亚洲人成在线电影| 毛片大全免费观看| 国产精品福利片免费看| 久久亚洲日韩看片无码| 免费萌白酱国产一区二区| 日韩精品内射视频免费观看| 亚洲色偷偷色噜噜狠狠99| 亚洲精品无码鲁网中文电影| 最近2019中文字幕免费看最新|