测试一下读取文本的另一种方法:该方法只使用一个类读取了文件

注意:buffer和read方法中读取指定长度的一致

package com.swust;
import java.io.*;
/*
* 数据流包括DataInputStream、DataOutputStream类,
* 两个类的实例化完成流的操作
*/
public class flowTest { public static void main(String[] args) {
byte buffer[]=new byte[2048];
// TODO Auto-generated method stub String path = "C:/test/1/" ;
String inforTxt = "1.txt";
String newPath=path+inforTxt; try{
FileInputStream fileInput = new FileInputStream(newPath);
int bytes=fileInput.read(buffer, 0, 2048);
String str=new String(buffer,0,bytes);
System.out.println(str);
fileInput.close();
}catch(Exception e){
System.out.println(e.toString());
} } }

读取效果:

你从国外回来咱就没怎么聊过
一直都在忙着其实有好多话想说
还没来得及转一眼又要回去了
兄弟
你这一走又是几年还真舍不得
都是大老爷们
说的有点女人了
又要离开了
你得惦记咱这哥几个
我好面儿
这些话太啰嗦有点说不出口
所以把它写成一首祝福的歌

最新文章

  1. 三列等高 css实现
  2. JavaScript中捕获/阻止捕获、冒泡/阻止冒泡
  3. Egret 摇一摇功能
  4. htpasswd 详解
  5. cf708B. Recover the String---(构造法)
  6. 修改Netbeans默认使用UTF-8编码
  7. eclipse 点击 open Implementation就退出eclipse
  8. Cows - POJ 3348(凸包求面积)
  9. mybatis日记配置Log4j
  10. 使用CountDownLatch和CyclicBarrier处理并发线程
  11. springboot 入门七-静态资源处理
  12. 提取微信小程序“头脑王者”业务逻辑
  13. 对于DFT频谱泄漏问题的研究
  14. LoadRunner 11 error:Cannot initialize driver dll
  15. themeleaf引入公共页面
  16. OneZero产品视频
  17. Highcharts 配置语法
  18. hightcharts 如何修改legend图例的样式
  19. 【delphi】TStringList类常用属性方法详解
  20. 关于Context []startup failed due to previous errors

热门文章

  1. 严重: Servlet.service() for servlet jsp threw exception java.lang.IllegalStateException: getOutputStream() has already been called for this response
  2. html的URL参数传值问题
  3. MySQL常用命令总结3
  4. C++中string类的使用方法
  5. Powerbuilder编程技巧 如何获取网页的HTML源码
  6. DrawerLayout学习笔记
  7. C语言-break和continue
  8. Statemen接口对象
  9. 忘记Django登陆账号和密码的处理方法
  10. [Angular Tutorial] 11 -Custom Filters