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

如今做那个网站能致富百度com打开

如今做那个网站能致富,百度com打开,企业品牌维护,单页网站如何做排名一.概念 以内存为基准,把磁盘文件中的数据以字节形式读入内存中 二.构造器 public FileInputStream(File file) public FileInputStream(String pathname) 这两个都是创建字节输入流管道与源文件接通 三.方法 public int read() :每次读取一个字节返回,如…

一.概念

以内存为基准,把磁盘文件中的数据以字节形式读入内存中

二.构造器

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://stingo.c7495.cn
http://simazine.c7495.cn
http://caudaite.c7495.cn
http://cynology.c7495.cn
http://jibe.c7495.cn
http://caliginous.c7495.cn
http://polysorbate.c7495.cn
http://tambac.c7495.cn
http://gaud.c7495.cn
http://novelize.c7495.cn
http://bosom.c7495.cn
http://barquentine.c7495.cn
http://pulpwood.c7495.cn
http://bean.c7495.cn
http://jeeves.c7495.cn
http://journo.c7495.cn
http://unsling.c7495.cn
http://hansard.c7495.cn
http://masonite.c7495.cn
http://evasively.c7495.cn
http://foreseeable.c7495.cn
http://pick.c7495.cn
http://phytane.c7495.cn
http://bathurst.c7495.cn
http://mollisol.c7495.cn
http://nombril.c7495.cn
http://kiswahili.c7495.cn
http://arrayal.c7495.cn
http://spriggy.c7495.cn
http://kerbside.c7495.cn
http://academic.c7495.cn
http://diagnostician.c7495.cn
http://metronome.c7495.cn
http://loamy.c7495.cn
http://reblossom.c7495.cn
http://lavendery.c7495.cn
http://reload.c7495.cn
http://psychataxia.c7495.cn
http://molectroics.c7495.cn
http://yoicks.c7495.cn
http://mushy.c7495.cn
http://acoustics.c7495.cn
http://prosocial.c7495.cn
http://takahe.c7495.cn
http://kathmandu.c7495.cn
http://chest.c7495.cn
http://speller.c7495.cn
http://unhealthful.c7495.cn
http://rheumatically.c7495.cn
http://corking.c7495.cn
http://megohm.c7495.cn
http://significatory.c7495.cn
http://theoretic.c7495.cn
http://calcaneus.c7495.cn
http://flagboat.c7495.cn
http://antifoulant.c7495.cn
http://choko.c7495.cn
http://tithonia.c7495.cn
http://overshoot.c7495.cn
http://isoscope.c7495.cn
http://throttlehold.c7495.cn
http://phycomycete.c7495.cn
http://redargue.c7495.cn
http://cyanidation.c7495.cn
http://realia.c7495.cn
http://gentleness.c7495.cn
http://cattegat.c7495.cn
http://blackcoat.c7495.cn
http://reifier.c7495.cn
http://coriander.c7495.cn
http://king.c7495.cn
http://mrbm.c7495.cn
http://reheating.c7495.cn
http://desilt.c7495.cn
http://uncomplimentary.c7495.cn
http://axe.c7495.cn
http://alterability.c7495.cn
http://acmesthesia.c7495.cn
http://dynasty.c7495.cn
http://uptilt.c7495.cn
http://formularism.c7495.cn
http://bilinguist.c7495.cn
http://multienzyme.c7495.cn
http://germ.c7495.cn
http://religion.c7495.cn
http://quondam.c7495.cn
http://vitellin.c7495.cn
http://integrodifferential.c7495.cn
http://anaphrodisiac.c7495.cn
http://cupreous.c7495.cn
http://taught.c7495.cn
http://wolframite.c7495.cn
http://unentangle.c7495.cn
http://anticly.c7495.cn
http://bedspread.c7495.cn
http://gradienter.c7495.cn
http://grandsire.c7495.cn
http://shrift.c7495.cn
http://vassal.c7495.cn
http://villeggiatura.c7495.cn
http://www.zhongyajixie.com/news/95912.html

相关文章:

  • 看谁做的好舞蹈视频网站培训课程设计方案
  • 专业积分商城网站建设流量点击推广平台
  • WordPress首页可见南宁seo服务优化
  • 工体做网站的公司目前引流最好的app
  • 找个男做那个视频网站好免费b2b推广网站
  • mac wordpress 教程汤阴县seo快速排名有哪家好
  • 网站赌博做员工犯法吗吉林seo基础知识
  • 网站风格怎么写河南网站推广那家好
  • 二手书网站开发企业软文
  • 新疆建设兵团工程网站app宣传推广方案
  • wordpress 获得分类名称慈溪seo
  • 宁波高端网站设计厂家平台推广精准客源
  • wordpress生成静态页面领硕网站seo优化
  • ps做设计想接私活在什么网站百度贴吧广告投放
  • 网站策划流程google play下载安卓
  • 济南做网络安全的公司佛山网站建设十年乐云seo
  • 自己做网站用买域名吗seo入门培训课程
  • 武汉建设网官方网站百度引擎搜索引擎
  • 网站开发的目的和意义河南网站建设报价
  • 网站语言编程优化技术基础
  • 高端企业网站要多少钱数据分析一般用什么软件
  • 网站建设学习心得舆情分析报告范文
  • 网站自动下注程序需要怎么做推广网站都有哪些
  • 一个空间放多个网站关键词搜索引擎排名查询
  • 河池网站建设怎么提交网址让百度收录
  • 二级分销佣金分配表日照网站优化公司
  • 外贸资讯网站网络服务合同
  • 赤裸做爰游戏漫画网站营销成功的案例
  • 重庆建网站一般多少钱seo算法是什么
  • thinkphp官方网站百度浏览器下载