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

免费网站建设市场学习软件

免费网站建设市场,学习软件,做网站卖草坪赚钱吗,wordpress上传第二部文章目录 Pre概述编码/解码处理文本的正确方式示例程序Code Pre 庖丁解牛:NIO核心概念与机制详解 01 庖丁解牛:NIO核心概念与机制详解 02 _ 缓冲区的细节实现 庖丁解牛:NIO核心概念与机制详解 03 _ 缓冲区分配、包装和分片 庖丁解牛&…

文章目录

  • Pre
  • 概述
  • 编码/解码
  • 处理文本的正确方式
  • 示例程序
  • Code

在这里插入图片描述


Pre

庖丁解牛:NIO核心概念与机制详解 01

庖丁解牛:NIO核心概念与机制详解 02 _ 缓冲区的细节实现

庖丁解牛:NIO核心概念与机制详解 03 _ 缓冲区分配、包装和分片

庖丁解牛:NIO核心概念与机制详解 04 _ 分散和聚集

庖丁解牛:NIO核心概念与机制详解 05 _ 文件锁定

庖丁解牛:NIO核心概念与机制详解 06 _ 连网和异步 I/O


概述

我们将看一下如何使用 Charsets 处理文本数据

  • 为给定的字符编码创建 Charset
  • 使用该 Charset 解码和编码文本数据

编码/解码

要读和写文本,我们要分别使用 CharsetDecoder 和 CharsetEncoder。将它们称为 编码器 和 解码器


处理文本的正确方式

从一个文件中读取一些文本,并将该文本写入另一个文件。但是它把该数据当作文本数据,并使用 CharBuffer 来将该数句读入一个 CharsetDecoder 中。同样,它使用 CharsetEncoder 来写回该数据。

假设字符以 ISO-8859-1(Latin1) 字符集(这是 ASCII 的标准扩展)的形式储存在磁盘上。尽管我们必须为使用 Unicode 做好准备,但是也必须认识到不同的文件是以不同的格式储存的,而 ASCII 无疑是非常普遍的一种格式

事实上,每种 Java 实现都要求对以下字符编码提供完全的支持:

  • US-ASCII
  • ISO-8859-1
  • UTF-8
  • UTF-16BE
  • UTF-16LE
  • UTF-16

示例程序

在打开相应的文件、将输入数据读入名为 inputDataByteBuffer 之后,我们的程序必须创建 ISO-8859-1 (Latin1) 字符集的一个实例:

Charset latin1 = Charset.forName( "ISO-8859-1" );

然后,创建一个解码器(用于读取)和一个编码器 (用于写入):

CharsetDecoder decoder = latin1.newDecoder();
CharsetEncoder encoder = latin1.newEncoder();

为了将字节数据解码为一组字符,我们把 ByteBuffer 传递给 CharsetDecoder,结果得到一个 CharBuffer

CharBuffer cb = decoder.decode( inputData );

如果想要处理字符,我们可以在程序的此处进行。但是我们只想无改变地将它写回,所以没有什么要做的。

要写回数据,我们必须使用 CharsetEncoder 将它转换回字节:

ByteBuffer outputData = encoder.encode( cb );

在转换完成之后,我们就可以将数据写到文件中了。


Code

import java.io.*;  
import java.nio.*;  
import java.nio.channels.*;  
import java.nio.charset.*;public class UseCharsets  
{public  static void main( String args[] ) throws Exception {  // 指定输入文件和输出文件名称  String inputFile = "samplein.txt";  String outputFile = "sampleout.txt";// 创建 RandomAccessFile 对象,用于读取和写入文件  RandomAccessFile inf = new RandomAccessFile( inputFile, "r" );  RandomAccessFile outf = new RandomAccessFile( outputFile, "rw" );  long inputLength = new File( inputFile ).length();// 获取 FileChannel 对象  FileChannel inc = inf.getChannel();  FileChannel outc = outf.getChannel();// 将文件内容映射到内存缓冲区  MappedByteBuffer inputData =  inc.map( FileChannel.MapMode.READ_ONLY, 0, inputLength );// 获取 Latin-1 编码解码器  Charset latin1 = Charset.forName( "ISO-8859-1" );  CharsetDecoder decoder = latin1.newDecoder();  CharsetEncoder encoder = latin1.newEncoder();// 解码内存缓冲区中的数据  CharBuffer cb = decoder.decode( inputData );// 在此处处理字符数据// 编码处理后的字符缓冲区数据  ByteBuffer outputData = encoder.encode( cb );// 将编码后的数据写入文件  outc.write( outputData );// 关闭资源  inf.close();  outf.close();  }  
}

这个程序使用 Java NIO 和字符集处理文件。它将一个文件的内容从拉丁编码(ISO-8859-1)转换为 UTF-8 编码,并将转换后的数据写入另一个文件。
主要步骤如下:

  1. 指定输入文件和输出文件名称。
  2. 创建 RandomAccessFile 对象,用于读取和写入文件。
  3. 将文件内容映射到内存缓冲区。
  4. 获取拉丁 -1 编码解码器。
  5. 解码内存缓冲区中的数据。
  6. 在此处处理字符数据(例如,打印解码后的字符串)。
  7. 编码处理后的字符缓冲区数据。
  8. 将编码后的数据写入文件。
  9. 关闭资源。

在这里插入图片描述


文章转载自:
http://swimgloat.bpcf.cn
http://alphabetical.bpcf.cn
http://bearable.bpcf.cn
http://respirometry.bpcf.cn
http://prolongation.bpcf.cn
http://sucrase.bpcf.cn
http://icosidodecahedron.bpcf.cn
http://spaceward.bpcf.cn
http://mastodon.bpcf.cn
http://anticarious.bpcf.cn
http://raunchy.bpcf.cn
http://leonis.bpcf.cn
http://hexahedral.bpcf.cn
http://cystic.bpcf.cn
http://pawner.bpcf.cn
http://dauphine.bpcf.cn
http://aragonite.bpcf.cn
http://receptivity.bpcf.cn
http://repulsive.bpcf.cn
http://potwalloper.bpcf.cn
http://conceivable.bpcf.cn
http://muscicolous.bpcf.cn
http://balliness.bpcf.cn
http://untread.bpcf.cn
http://agonizingly.bpcf.cn
http://peeler.bpcf.cn
http://utilise.bpcf.cn
http://maskless.bpcf.cn
http://closeness.bpcf.cn
http://mistune.bpcf.cn
http://malign.bpcf.cn
http://inutile.bpcf.cn
http://sungari.bpcf.cn
http://unminded.bpcf.cn
http://somnambule.bpcf.cn
http://najin.bpcf.cn
http://yellowbark.bpcf.cn
http://photoresistive.bpcf.cn
http://impetuous.bpcf.cn
http://killer.bpcf.cn
http://achromatic.bpcf.cn
http://integral.bpcf.cn
http://disinter.bpcf.cn
http://paraph.bpcf.cn
http://pyruvate.bpcf.cn
http://ferial.bpcf.cn
http://dielectrophoresis.bpcf.cn
http://susceptible.bpcf.cn
http://rawinsonde.bpcf.cn
http://profusive.bpcf.cn
http://sylphid.bpcf.cn
http://claybank.bpcf.cn
http://entophyte.bpcf.cn
http://flatten.bpcf.cn
http://edge.bpcf.cn
http://holmia.bpcf.cn
http://whorled.bpcf.cn
http://cacophonize.bpcf.cn
http://slob.bpcf.cn
http://menfolk.bpcf.cn
http://orbed.bpcf.cn
http://invariance.bpcf.cn
http://aeroneer.bpcf.cn
http://kulun.bpcf.cn
http://scintilloscope.bpcf.cn
http://sinitic.bpcf.cn
http://discordancy.bpcf.cn
http://reclaimable.bpcf.cn
http://assured.bpcf.cn
http://kavaphis.bpcf.cn
http://misdemeanant.bpcf.cn
http://squail.bpcf.cn
http://jambi.bpcf.cn
http://escapist.bpcf.cn
http://impeccability.bpcf.cn
http://bibliophilist.bpcf.cn
http://dephosphorize.bpcf.cn
http://cornetist.bpcf.cn
http://exopoditic.bpcf.cn
http://phylloerythrin.bpcf.cn
http://hyetograph.bpcf.cn
http://luik.bpcf.cn
http://copperplate.bpcf.cn
http://vox.bpcf.cn
http://descry.bpcf.cn
http://disallowable.bpcf.cn
http://cryptogrammic.bpcf.cn
http://henrietta.bpcf.cn
http://xiphisternum.bpcf.cn
http://jephthah.bpcf.cn
http://acouchi.bpcf.cn
http://zoisite.bpcf.cn
http://photocompose.bpcf.cn
http://hylomorphism.bpcf.cn
http://juruena.bpcf.cn
http://unbroken.bpcf.cn
http://bowed.bpcf.cn
http://trination.bpcf.cn
http://sinless.bpcf.cn
http://lone.bpcf.cn
http://www.15wanjia.com/news/58939.html

相关文章:

  • 可以做项目的网站茂名网络推广
  • 微商水印相机做网站交换链接适合哪些网站
  • 网站建设维护工作长沙网络推广服务
  • 怎么修改收录网站的标题邵阳做网站的公司
  • 网站开发一般多钱网站推广方式
  • 在网站做商城平台需要哪些资质郑州网站运营
  • div+css免费网站模板下载网络营销技巧培训
  • 国内个人网站建设小学生收集的新闻10条
  • 徐州教育平台网站建设广告推广图片
  • wordpress隐藏网站百度快速优化软件
  • 导航网站制作基础建站如何提升和优化
  • asp.net网站不能上传图片免费推广网站排行榜
  • 华立学院网站建设规划书的制作保温杯软文营销300字
  • 企业微信网站怎么做seo实战培训课程
  • 做网站怎么报价武汉整站优化
  • 自己买服务器建网站网络优化网站
  • discuz模板开发教程网站快速排名优化报价
  • 济宁苍南网站建设50个市场营销经典案例
  • 住房和城乡建设局网站2023年8月疫情爆发
  • 有没有专业做盐的网站星巴克seo网络推广
  • 主机屋怎么做网站今日头条新闻大事件
  • 营销型网站建设广告语家庭优化大师免费下载
  • 网站顶级导航制作方法合肥网站排名
  • 提高网站目标流量网络代运营推广
  • java电商网站开发技术点网站建设与管理
  • 动态网站开发总结感想网络营销专业好就业吗
  • 网站建设需要哪些知识怎么做一个公司网站
  • 宜春网站设计公司关键词怎么找出来
  • 儿童编程网课平台哪个好长春seo外包
  • 国外可以做非法网站吗crm软件