当前位置:
首页 >
io流文本文档的快速读取
发布时间:2024/8/26
52
豆豆
生活随笔
收集整理的这篇文章主要介绍了
io流文本文档的快速读取
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
package com.ute.action;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
/**
*
* @author Administrator
* 文本文档的快速读取
*/
public class action {
public static void main(String[] args) {
Long start=System.currentTimeMillis();
action.teIO();
}
public static void teIO(){
//通过反射的方式获取流对象
File file1 = new File(action.class.getResource("utest.txt").getFile());
System.out.println("文件是否存在测试:"+file1.exists());//true
FileReader fr = null;
try {
fr= new FileReader(file1);
//修改每次读取的个数,一般为2进制递进64-128-256-512-1024
char [] c=new char[64];
while (fr.read(c) != -1) {
System.out.println(c);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally {
try {
//关闭读取流
fr.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
/**
*
* @author Administrator
* 文本文档的快速读取
*/
public class action {
public static void main(String[] args) {
Long start=System.currentTimeMillis();
action.teIO();
Long end=System.currentTimeMillis();
System.out.print("用时");
}
public static void teIO(){
//通过反射的方式获取流对象
File file1 = new File(action.class.getResource("utest.txt").getFile());
System.out.println("文件是否存在测试:"+file1.exists());//true
FileReader fr = null;
try {
fr= new FileReader(file1);
//修改每次读取的个数,一般为2进制递进64-128-256-512-1024
char [] c=new char[64];
while (fr.read(c) != -1) {
System.out.println(c);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally {
try {
//关闭读取流
fr.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
总结
以上是生活随笔为你收集整理的io流文本文档的快速读取的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: centos安装 TA-Lib
- 下一篇: 对doget和dopost区别的理解