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

建立网站的优势用vs2012做网站教程

建立网站的优势,用vs2012做网站教程,钱追得回吗,微企点建好网站后要怎么做一.概念 以内存为基准#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.eeditor.cn/news/122441/

相关文章:

  • 河间市做网站郑州网站推广哪家效果好
  • 怎么看别人网站是怎么做的网站vr的建设
  • 安装字体怎么在wordpressseo排名如何优化
  • 网站建设销售专业话术网站东莞优化建设
  • 建e网官方网站公司网站建设系统
  • 织梦cms网站模板修改如何做优化网站排名
  • 温州做网站建设多少钱网站建设的新发展
  • 网易梦幻西游手游官方网站下载品牌建设需打持久战
  • 杭州城西做网站的公司龙岩做网站的公司
  • 网站设计ai西安网站建设定制
  • 网站首页图片做多大哈尔滨的网站建设公司
  • php商城网站开发实例视频教程公司注册地址必须是商业用房吗
  • 辽阳企业网站建设费如何建立自己的网拍平台
  • 没有网站可以做app吗专业网站建设一条龙
  • 人事管理软件seo互联网营销培训
  • 枣庄建设网站做网站白云区
  • 镇江网站建设网站制作公司网络营销swot分析
  • 朝阳网站建设开发百度网站建设优化
  • 简约风格网站建设一些简约大气的网站
  • 天津微信网站建设国家建设部官方网站
  • 一家做公司评估的网站免费找订单的平台
  • 做带字头像的网站什么网站的页面好看
  • 做pc端网站信息wordpress move zip
  • 购物网站开发 英文文献有哪些做投行网站
  • phthon网站开发在哪家网站做外贸比较好
  • 蜜芽免费网站域名做餐饮网站建设
  • 网站优化建设兰州网站建设人员春招计划
  • 建设网站公司 销售额 排行静态网站flash
  • 做网站的实验总结静态网页模板下载后怎么修改
  • 松江新城做网站网站建设设计案例网站logo实验报告