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

wordpress 双 切换深圳知名seo公司

wordpress 双 切换,深圳知名seo公司,网络服务商主要包括哪些方面,传媒网站设计一.概念 以内存为基准#xff0c;把磁盘文件中的数据以字节形式读入内存中 二.构造器 public FileInputStream(File file) public FileInputStream(String pathname) 这两个都是创建字节输入流管道与源文件接通 三.方法 public int read() :每次读取一个字节返回#xff0c;如…一.概念 以内存为基准把磁盘文件中的数据以字节形式读入内存中 二.构造器 public FileInputStream(File file) public FileInputStream(String pathname) 这两个都是创建字节输入流管道与源文件接通 三.方法 public int read() :每次读取一个字节返回如果发现没有数据可读返回-1。 public int read(byte[] buffer) :每次用一个字节数组读取数据返回字节数组读取了多少字节如果发现没有数据可读返回-1. 四.执行 方法一一个一个字节读 1.代码 package org.example;import java.io.*;public class day05 {public static void main(String[] args) throws IOException {//1.创建文件字节输入流管道与源文件接通:两种方法都行InputStream f1 new FileInputStream(new File(D:\\temp\\day05\\a.txt));InputStream f2 new FileInputStream(D:\\temp\\day05\\a.txt);//2.读取文件的字节数据int b1 f1.read();System.out.println(b1);System.out.println((char) b1);int b2 f1.read();System.out.println(b2);System.out.println((char) b2);int b3 f1.read();System.out.println(b3);} }2.结果 上面代码一个一个字节读太麻烦了而且读取汉字会乱码下面进行优化 方法二循环读 1.代码 package org.example;import java.io.*;public class day05 {public static void main(String[] args) throws IOException {InputStream f1 new FileInputStream(D:\\temp\\day05\\b.txt);int b; //用于记住读取的字节while((b f1.read()) ! -1){System.out.print((char)b);}f1.close();} }上面代码读取性能很差且读取汉字会乱码需要进一步改进 ;流使用完必须要关闭释放系统资源。 2.结果 方法三每次读取多个字节 1.代码 package org.example;import java.io.*;public class day05 {public static void main(String[] args) throws IOException {//b.txt内容abcdefgInputStream f1 new FileInputStream(D:\\temp\\day05\\b.txt);//开始读取文件中的字节数据每次读取多个字节byte[] buffer new byte[4];int len f1.read(buffer);String s new String(buffer);System.out.println(s);System.out.println(读取的字节数len);int len2 f1.read(buffer);String s2 new String(buffer);System.out.println(s2);System.out.println(读取的字节数len2);f1.close();} }2.结果 正常情况下第二次读取的结果应该是efg而不是efgd 3.改进 package org.example;import java.io.*;public class day05 {public static void main(String[] args) throws IOException {//b.txt内容abcdefgInputStream f1 new FileInputStream(D:\\temp\\day05\\b.txt);//开始读取文件中的字节数据每次读取多个字节byte[] buffer new byte[4];int len f1.read(buffer);String s new String(buffer);System.out.println(s);System.out.println(读取的字节数len);int len2 f1.read(buffer);String s2 new String(buffer,0,len2);System.out.println(s2);System.out.println(读取的字节数len2);f1.close();} }4.结果  这个代码有待优化用循环进一步优化 方法四循环读取 1.代码 package org.example;import java.io.*;public class day05 {public static void main(String[] args) throws IOException {//b.txt内容abcdefgInputStream f1 new FileInputStream(D:\\temp\\day05\\b.txt);//开始读取文件中的字节数据每次读取多个字节byte[] buffer new byte[4];int len;while ((len f1.read(buffer)) ! -1) {String s new String(buffer, 0, len);System.out.print(s);}f1.close();} }2.结果 五.问题  上面代码读取性能提升了但依旧在读取汉字上会产生乱码 解决方案一定义一个与文件一样大的字节数组一次性读取完文件的全部字节不推荐 方法1 1.代码 package org.example;import java.io.*;public class day05 {public static void main(String[] args) throws IOException {//c.txt内容我们在一起abcdInputStream f1 new FileInputStream(D:\\temp\\day05\\c.txt);//这里的19可以用f1.length()获取byte[] buffer new byte[19];int len;while ((len f1.read(buffer)) ! -1) {String s new String(buffer, 0, len);System.out.print(s);}f1.close();} }2.结果 方法2 1.代码 package org.example;import java.io.*;public class day05 {public static void main(String[] args) throws IOException {//c.txt内容我们在一起abcdInputStream f1 new FileInputStream(D:\\temp\\day05\\c.txt);final byte[] bytes f1.readAllBytes();System.out.println(new String(bytes));} }2.结果 上面代码还有待优化万一文件特别大用readAllBytes()会抛出异常。
http://www.w-s-a.com/news/29874/

相关文章:

  • 网站里的专题页面wordpress查询数据库结构
  • WordPress子站站群网站建设代码生成器
  • 怎么攻击织梦网站甘肃省最新消息今天
  • 赣州哪里可以做网站看装修案例的网站
  • 旅游网站专业化建设的要点php 手机网站 模板
  • wordpress百度站长主动推送长春火车站官网
  • 比较好的响应式网站wordpress博客增加音乐页面
  • 广告公司出售家具 税率江门做网站seo的
  • 网站设计建议建设商务网站作用
  • 网站策划的最终体现是什么模板网站建设流程图
  • 网站设计与开发技术教程十度公司做网站怎么样
  • 企业网站推广方案在哪里智慧团建登录入口官网手机版
  • google网页版入口seo索引擎优化
  • 东乡做网站常州网络公司联系方式
  • 做网站激励语家居装饰网站设计论文
  • 镜像的网站怎么做排名无极网站建设质量
  • 奉贤集团公司网站建设小工具文本wordpress
  • 不用代码做网站网站建设和运行费用
  • 阜阳网站开发招聘网站建设合作协议申请
  • 电子配件 技术支持 东莞网站建设wordpress 生成html代码
  • 网站用免费空间好不好网站建设的视频
  • 网站开发项目职责门户资源分享网站模板
  • 建网站需要什么语言如何做二维码跳转到网站
  • 天津建设交培训中心网站做网站起名字
  • 黑河北京网站建设湛江市住房和城乡建设局网站
  • 网站建设拾金手指下拉十九企业查询官网
  • 邢台提供网站建设公司哪家好五合一建站
  • 京东网站设计代码驻马店做网站的公司
  • 织梦网站模板使用教程福州网站建设工作
  • 做网站要准备的需求asp 网站后台