文件的输入与输出
2015-11-23 21:06
381 查看
import java.io.*; import java.util.Scanner; import java.io.FileOutputStream; public class Readdata { public static void main(String[] args) throws IOException{ Scanner sc = null; try{ String path = "E:/test.txt"; sc = new Scanner(new File("E:/test.txt")); // 从文件中读取数据 File file = new File(path); if(!file.exists()){ file.createNewFile(); } else { FileInputStream test = new FileInputStream(file); byte[] byt = new byte[1024]; int len = test.read(byt); System.out.println("文件的信息是:\n"+new String(byt,0,len)); } }catch(FileNotFoundException e){ e.printStackTrace(); System.exit(0); } sc.close();//关闭操作 } }
## 结果 ##
相关文章推荐
- Xcode 7上传报错:ERROR ITMS-90535 解决办法
- ORA-12154: TNS:could not resolve the connect identifier specified
- 封装JPA的数据操作DAO类
- neo4j的安装
- LightOJ 1032 Fast Bit Calculations(数位DP)
- 为什么要乘以unity_Scale.w?
- Android实战技巧之九:最新Android开发环境(Eclipse+ADT+Android 5.0)
- 黑马程序员——Java笔记——接口
- 求n^k的前缀和
- HDU 1874 畅通工程续
- Git -- 不错的指导
- spring项目中dubbo相关的配置文件出现红叉的问题
- topcoder13185 TreePuzzle
- 如何压缩虚拟机文件
- mapreduce Wordcount输入文件在hdfs上的实例
- ViewPager+Indicator(如何写indicator)
- 内存管理:内存泄漏和空悬指针
- FC400A与400B的区别
- ViewPager 详解(一)---基本入门
- MATLAB的cat()函数