java 文件操作 读取txt文本(兄弟常开心)
2024-10-16 01:15:46
测试一下读取文本的另一种方法:该方法只使用一个类读取了文件
注意: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());
} } }
读取效果:
你从国外回来咱就没怎么聊过
一直都在忙着其实有好多话想说
还没来得及转一眼又要回去了
兄弟
你这一走又是几年还真舍不得
都是大老爷们
说的有点女人了
又要离开了
你得惦记咱这哥几个
我好面儿
这些话太啰嗦有点说不出口
所以把它写成一首祝福的歌
最新文章
- 三列等高 css实现
- JavaScript中捕获/阻止捕获、冒泡/阻止冒泡
- Egret 摇一摇功能
- htpasswd 详解
- cf708B. Recover the String---(构造法)
- 修改Netbeans默认使用UTF-8编码
- eclipse 点击 open Implementation就退出eclipse
- Cows - POJ 3348(凸包求面积)
- mybatis日记配置Log4j
- 使用CountDownLatch和CyclicBarrier处理并发线程
- springboot 入门七-静态资源处理
- 提取微信小程序“头脑王者”业务逻辑
- 对于DFT频谱泄漏问题的研究
- LoadRunner 11 error:Cannot initialize driver dll
- themeleaf引入公共页面
- OneZero产品视频
- Highcharts 配置语法
- hightcharts 如何修改legend图例的样式
- 【delphi】TStringList类常用属性方法详解
- 关于Context []startup failed due to previous errors
热门文章
- 严重: Servlet.service() for servlet jsp threw exception java.lang.IllegalStateException: getOutputStream() has already been called for this response
- html的URL参数传值问题
- MySQL常用命令总结3
- C++中string类的使用方法
- Powerbuilder编程技巧 如何获取网页的HTML源码
- DrawerLayout学习笔记
- C语言-break和continue
- Statemen接口对象
- 忘记Django登陆账号和密码的处理方法
- [Angular Tutorial] 11 -Custom Filters