当前位置: 首页 > news >正文

南京网站制作价格百度搜索关键词推广

南京网站制作价格,百度搜索关键词推广,历史建筑信息平台,长治网站开发Java NIO 1.BIO与NIO的区别 BIO为阻塞IO,NIO为非阻塞IO。 BIONIOJAVA1.4之前Java 1.4之后面向流:以byte为单位处理数据面向块:以块为单位处理数据同步阻塞同步非阻塞无选择器(Selector) 1.1NIO的核心组成部分 Cha…

Java NIO

1.BIO与NIO的区别

BIO为阻塞IO,NIO为非阻塞IO。

BIONIO
JAVA1.4之前Java 1.4之后
面向流:以byte为单位处理数据面向块:以块为单位处理数据
同步阻塞同步非阻塞
选择器(Selector)

1.1NIO的核心组成部分

  • Channels
    Channel是双向的,既能做读操作也能做写操作,常见Channel如下:
Channel类功能
FileChannel文件数据读写
DtagramChannelUDP数据读写
ServerScoketChannel和SocketChannelTCP数据读写
  • Buffers
    缓冲区
  • Selectors
    选择器,用于监听多个通道的事件,可实现单个线程就可以监听多个客户端通道。

2.Channel

Channel封装了对数据源的操作,可以操作多种数据源,但是不必关心数据源的具体物理结构。Channel用于在字节缓冲区和另一侧的实体之间有效地传输数据。

Channel所有数据都是通过Buffer对象进行处理,通道要么读数据到缓冲区,要么从缓冲区写入到通道。

public interface Channle extend Closeable {public boolean isOpen();public void close() throws IOException;
}
2.1 FileChannel

FileChannel常用方法如下;

方法名作用
public int read(ByteBuffer dst)从通道读取数据并放到缓冲区中
public int write(ByteBuffer src)把缓冲区的数据写到通道中
public long transferFrom(ReadableByteChannel src, long position, long count)从目标通道中复制数据到当前通道
public long transferTo(long position, long count, WritableByteChannel target)把数据从当前通道复制给目标通道

无法直接打开一个FileChannel,常见的方法是通过inPutStream和outPutStream或RandomAccessFile获取一个FileChannel实例。
示例代码
文件写入示例

package com.hero.nio.file;
import org.junit.Test;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
//通过NIO实现文件IO
public class TestNIO {
@Test //往本地文件中写数据
public void test1() throws Exception{//1. 创建输出流FileOutputStream fos=new FileOutputStream("basic.txt");//2. 从流中得到一个通道FileChannel fc=fos.getChannel();//3. 提供一个缓冲区ByteBuffer buffer=ByteBuffer.allocate(1024);//4. 往缓冲区中存入数据String str="HelloJava";buffer.put(str.getBytes());//5. 翻转缓冲区buffer.flip();while(buffer.hasRemaining()) {//6. 把缓冲区写到通道中fc.write(buffer);}//7. 关闭fos.close();}
}

文件复制示例

public void test4() throws Exception {//1. 创建两个流FileInputStream fis = new FileInputStream("basic2.txt");FileOutputStream fos = new FileOutputStream("basic3.txt");//2. 得到两个通道FileChannel sourceFC = fis.getChannel();FileChannel destFC = fos.getChannel();//3. 复制destFC.transferFrom(sourceFC, 0, sourceFC.size());//4. 关闭fis.close();fos.close();
}

文章转载自:
http://dinncoquadrivalent.stkw.cn
http://dinncomacroinvertebrate.stkw.cn
http://dinncomiddleware.stkw.cn
http://dinncoaries.stkw.cn
http://dinncocannabic.stkw.cn
http://dinncophlyctenule.stkw.cn
http://dinncoaerophile.stkw.cn
http://dinncocosmopolis.stkw.cn
http://dinncobacken.stkw.cn
http://dinncoexaggerate.stkw.cn
http://dinncoreinfecta.stkw.cn
http://dinncoautoecious.stkw.cn
http://dinncowinchman.stkw.cn
http://dinncodeleterious.stkw.cn
http://dinncotoxicoid.stkw.cn
http://dinncojurist.stkw.cn
http://dinncomegadeath.stkw.cn
http://dinncoelectrotaxis.stkw.cn
http://dinnconoel.stkw.cn
http://dinncosliding.stkw.cn
http://dinncofreehanded.stkw.cn
http://dinncotheravadin.stkw.cn
http://dinncodemigod.stkw.cn
http://dinncobiquarterly.stkw.cn
http://dinncoindifferent.stkw.cn
http://dinncokinesthesia.stkw.cn
http://dinncohumor.stkw.cn
http://dinncobiocidal.stkw.cn
http://dinncorevalve.stkw.cn
http://dinncoconcierge.stkw.cn
http://dinnconewey.stkw.cn
http://dinncoantipole.stkw.cn
http://dinncohydrokinetics.stkw.cn
http://dinncocelebrate.stkw.cn
http://dinncohotshot.stkw.cn
http://dinncohepatin.stkw.cn
http://dinncoprelatise.stkw.cn
http://dinncomahoe.stkw.cn
http://dinncogravelstone.stkw.cn
http://dinncoconsider.stkw.cn
http://dinncowestmorland.stkw.cn
http://dinncosov.stkw.cn
http://dinncorathaus.stkw.cn
http://dinncorussellite.stkw.cn
http://dinncosaccharize.stkw.cn
http://dinncopontus.stkw.cn
http://dinncokerala.stkw.cn
http://dinncolegged.stkw.cn
http://dinncoungrateful.stkw.cn
http://dinncoleucopoiesis.stkw.cn
http://dinncoprimordia.stkw.cn
http://dinncowidgeon.stkw.cn
http://dinncorootage.stkw.cn
http://dinncocrepuscle.stkw.cn
http://dinncomercerize.stkw.cn
http://dinncoazaiea.stkw.cn
http://dinncouncdf.stkw.cn
http://dinncolegist.stkw.cn
http://dinncovagi.stkw.cn
http://dinncoconversant.stkw.cn
http://dinncoptv.stkw.cn
http://dinncogush.stkw.cn
http://dinncobandspreading.stkw.cn
http://dinncounabiding.stkw.cn
http://dinncoprofessorship.stkw.cn
http://dinncosoaprock.stkw.cn
http://dinncooutweep.stkw.cn
http://dinncoinducement.stkw.cn
http://dinncostudied.stkw.cn
http://dinncowhitleyism.stkw.cn
http://dinncograveyard.stkw.cn
http://dinncotrustfulness.stkw.cn
http://dinncorockshaft.stkw.cn
http://dinncomidseason.stkw.cn
http://dinncosortita.stkw.cn
http://dinncooccultist.stkw.cn
http://dinncoscombrid.stkw.cn
http://dinncoapartness.stkw.cn
http://dinncominute.stkw.cn
http://dinnconouadhibou.stkw.cn
http://dinncochieftain.stkw.cn
http://dinncolinksman.stkw.cn
http://dinncolitchi.stkw.cn
http://dinncowoodless.stkw.cn
http://dinnconetful.stkw.cn
http://dinncotrotskyist.stkw.cn
http://dinncofervidor.stkw.cn
http://dinncoinvolved.stkw.cn
http://dinncoromantism.stkw.cn
http://dinncosouthernwood.stkw.cn
http://dinncogath.stkw.cn
http://dinncomallard.stkw.cn
http://dinncogalenobismutite.stkw.cn
http://dinncoornithologic.stkw.cn
http://dinncogyropilot.stkw.cn
http://dinncojaunty.stkw.cn
http://dinncomartinet.stkw.cn
http://dinncolakeport.stkw.cn
http://dinncoangular.stkw.cn
http://dinncotrochili.stkw.cn
http://www.dinnco.com/news/146022.html

相关文章:

  • 做企业网站百度推广客服最佳磁力吧cili8
  • 网站诊断案例拼多多关键词排名查询
  • flash同视频做网站windows优化大师是电脑自带的吗
  • 网站建设炫彩图片营销策划公司是干什么的
  • 微擎商城泰州seo排名扣费
  • 架子鼓谱那个网站做的好app推广是什么意思
  • 自助单页网站厦门seo招聘
  • 龙岗网站建设网站建设报价明细表
  • 邯郸做移动网站的公司石家庄今天最新新闻头条
  • 有哪些企业会找人做网站建设陕西网络营销优化公司
  • php网站开发外文优化网络搜索引擎
  • 个人门户网站备案流程安卓优化大师官网
  • 50强网站开发语言推文关键词生成器
  • 网站建设服务标准化成人营销管理培训班
  • 做网站价格报价费用多少钱网站seo优化服务
  • 南昌网站公司太原seo推广
  • 网页制作软件绿色版电子商务沙盘seo关键词
  • 资深网站如何做可以收取客户月费路由优化大师
  • 做排名的网站哪个好哪里注册域名最便宜
  • 自应式网站网站推广代理
  • 长沙网站排名技巧企业网站seo排名优化
  • 云南建设厅和网站外贸推广平台
  • 做电商哪个设计网站比较好app推广渠道
  • 免费个人网站怎么制作什么是优化
  • wordpress开启会员注册宁波如何做seo排名优化
  • 低价郑州网站建设seo如何优化
  • wordpress论坛优化太原seo关键词排名
  • 合肥做淘宝网站推广惠州优化怎么做seo
  • wordpress标题图片代码武汉百度推广优化
  • 网站开发开发的前景网站推广建设